code: def post_order(parent):
      
      n = len(parent)
      k = 0
  
      p = matrix(0,(n,1))
      head = matrix(-1,(n,1))
      next = matrix(0,(n,1))
      stack = matrix(0,(n,1))
  
      for j in range(n-1,-1,-1):
          if (parent[j] == j): continue
          next[j] = head[parent[j]]
          head[parent[j]] = j
  
      for j in range(n):
          if (parent[j] != j): continue
          k = __tdfs(j, k, head, next, p, stack)
  
      return p
docs: Post order a forest.