#T325. 家谱树

家谱树

Description

A person's family is very large, and the generational relationships are quite chaotic. Please help organize these relationships.
Given information about each person's children, output a sequence where every descendant appears after their ancestor.

Input Format

  • The first line contains an integer ( N ) (( 1 \leq N \leq 100 )), representing the number of family members.
  • The next ( N ) lines describe the children of each person.
    • Line ( I ) describes the children of person ( I ).
    • Each line ends with a 0, indicating the end of the list.

Output Format

Output a sequence where every descendant appears after their ancestor.
If there are multiple valid solutions, any one is acceptable.

5
0
4 5 1 0
1 0
5 3 0
3 0

2 4 5 3 1