<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def post_order(parent):
 """ Post order a forest. """

    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