#t534. 家谱树
家谱树
Family Ordering
Special for beginners, ^_^
Problem Description
Someone has a large family whose generational relationships are very tangled. Please help sort them out.
You are given information about each person's children.
Output a sequence such that every person's descendants are listed after that person.
Input Format
Line 1: an integer (), the number of people in the family.
The next lines: line describes the sons of person .
Each line ends with 0 to mark the end of the description.
Output Format
Output a sequence such that every person's descendants are listed after that person.
If multiple solutions exist, output any one.
Sample Input 1
5
0
4 5 1 0
1 0
5 3 0
3 0
Sample Output 1
2 4 5 3 1
Constraints
1s, 1024KiB for each test case.