-->
当前位置:首页 > 题库

PROGRAMMING:Xiaozi generation (left son and right brother)

Luz5年前 (2021-05-10)题库393
Given the genealogy of a large family, please give the list of the youngest generation< br>
It should be noted that the input method of family members follows the format of "left child right sibling" < br > and "left child right sibling" is used to input family members
[knocking on the blackboard] sibling means brother / sister, not "cousin"! Children who don't know the word "sibling" in pat in the spring of 2019, please remember.... < br > this is the first time to learn the word "sibling"
*Note: this question is adapted from the meaning of "xiaoziren" in l2-2 of gplt-2018 final by Chen Yue of Zhejiang University*
###Input format:
Enter in the first line to give the family population n (a positive integer not exceeding 100000) - for simplicity, we number the family members from 1 to n< br>
In the following N lines, each line gives the number of a family member and his kinship, in the form of three integers' a ','b','c ', < br > separated by spaces
The 'a' (range 1-N) is the number of a family member (the number of each line must be different) < br > the number of each family member is the same
`The range of B is 0-n. when B is not 0, it means that a has a son B< br>
`The range of "C" is 0 to N. when "C" is not 0, it means that "a" has a brother "C"< br>
The title ensures that the input is correct, i.e. there is only one family (not separated into a family group) and there is only one ancestor in the family (ancestor: he is not the son of anyone else)
###Output format:
First, output the smallest generation (the number of ancestors is the largest and the number is 1, and the number of descendants is increased by 1 step by step)< br>
Then in the second line, the number of the member with the smallest generation is output in ascending order. The numbers shall be separated by a space, and there shall be no extra space at the beginning and end of the line.
###Input sample 1:
```in
five
1 2 0
2 4 3
3 0 0
4 0 5
5 0 0
```
###Output sample 1:
```out
three
4 5
```
###Input sample 2:
```in
five
2 5 3
1 2 0
3 0 0
4 0 0
5 0 4
```
###Output sample 2:
```out
three
4 5
```







answer:If there is no answer, please comment