spoj TREEORD - Tree _order

How can I solve http://www.spoj.com/problems/TREEORD/ problem please provide some efficient algorithm to solve it