PROGRAMMING:List all ancestor nodes
For a given binary tree, this problem requires you to output all the ancestor nodes of the specified node from top to bottom.
###Input format:
First, the first line gives a positive integer n (≤ 10), which is the total number of nodes in the tree. The nodes in the tree are numbered from 0 to n − 1.
Then n lines, each line gives a number of the left and right children of the corresponding node. If a child doesn't exist, give a '-' in the corresponding position. The numbers are separated by a space.
The last line gives a node number I (0 ≤ I ≤ n-1).
###Output format:
In a row, output the number of all ancestor nodes of I in the specified order. The numbers shall be separated by one space, and there shall be no extra space at the beginning and end of the line.
###Input example:
```in
seven
2 -
- 6
- -
0 5
- -
4 1
- -
four
```
###Output example:
```out
3 5
```
answer:If there is no answer, please comment
###Input format:
First, the first line gives a positive integer n (≤ 10), which is the total number of nodes in the tree. The nodes in the tree are numbered from 0 to n − 1.
Then n lines, each line gives a number of the left and right children of the corresponding node. If a child doesn't exist, give a '-' in the corresponding position. The numbers are separated by a space.
The last line gives a node number I (0 ≤ I ≤ n-1).
###Output format:
In a row, output the number of all ancestor nodes of I in the specified order. The numbers shall be separated by one space, and there shall be no extra space at the beginning and end of the line.
###Input example:
```in
seven
2 -
- 6
- -
0 5
- -
4 1
- -
four
```
###Output example:
```out
3 5
```
answer:If there is no answer, please comment