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

PROGRAMMING:GG's genealogy

Luz5年前 (2021-05-10)题库384
GG turns to the genealogy of his family. He is eager to know the information about the great grandchildren of each ancestor in the genealogy to calculate his family status. But the whole genealogy is too big. Counting one by one is a very tiring job. GG asked for your help, I hope you can help him!
The GG family has a very special rule, that is, a person can have at most two sons / daughters. If he has more than two sons / daughters, he will be expelled from the family and will never appear in the genealogy again. In order to facilitate you to focus more on solving this problem, GG's friend Xiao Z has numbered everyone in the genealogy. Your task is to calculate the given number of people, who his great grandson is!
###Input format:
The first line gives a positive integer n (n < = 100) to represent the total number of people in the genealogy!
Next N lines each line contains three numbers num, l, R, which respectively represent the node number and its two child numbers. If it does not exist, it is represented by - 1!
The next line contains a positive integer Q that represents the number of queries( q<=10)
Next, line Q, each line contains a 1-N positive integer and a string representing the node number of the query. The string is given in this form:
"mygrandgrandgrand..grandson"
There are several grands, please output the number of their grandsons!
It is worth noting that son also needs to be counted as a generation, which is not too difficult for you who are good at English( I.e. grandson for the next two generations, grandson for the next three generations)
The title guarantees that the string must start with "my", and "grand" must be between "my" and "son", and there is at most one "son" at the end, but it does not guarantee that the string must have "son"!
###Output format:
Please output the corresponding node number of each query in ascending order in one line! If there is no corresponding node number, please output "none!!!"
Don't have extra space at the end!
###Input example:
Here is a set of inputs. For example:
```in
six
1 2 3
2 4 5
3 6 -1
4 -1 -1
5 -1 -1
6 -1 -1
two
1 mygrandson
1 mygrandgrandson
```
###Output example:
The corresponding output is given here. For example:
```out
4 5 6
None!!!
```







answer:If there is no answer, please comment