Problem2013--List Leaves

2013: List Leaves

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1381  Solved: 856
[Submit] [Status] [Web Board] [Creator:]

Description

Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.

Input

Each input file contains one test case. For each case, the first line gives a positive integer N (≤10) which is the total number of nodes in the tree -- and hence the nodes are numbered from 0 to N−1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a

Output

For each test case, print in one line all the leaves

Sample Input Copy

8
1 -
- -
0 -
2 7
- -
- -
5 -
4 6

Sample Output Copy

4 1 5

Source/Category

167