2283. Domino Course

单点时限: 2.0 sec

内存限制: 256 MB

Your little brother got a Domino course for Christmas. He locked up the living room to be undisturbed building a big big course. After your parents became very angry he opened the door and showed his masterpiece to you smiling proudly. “If I start the course now”, he says, “all of these Dominos will fall, but in the moment the last one is falling, how many will go with it?”

To simplify it a little bit: All Dominos need the same time to fall and are numbered with 1,2,…,N. If the course splits up into two or more lines they will all fall simultaneously. Every Domino has at most one other (not necessary a different Domino) which will cause him to fall. If all of them can be reached print out the numbers of all Dominos (sorted by number!) falling in the very last moment. If some Dominos can’t be reached print their numbers. (Don’t tell me whether they fall or not.)

输入格式

As input you get lines containing one or more integers. The first number specifies the number of the following test cases. All of these have the following format: The first integer is the number N of Dominos in this course. The second integer is the number of the one which will be knocked by me. On the next line you get N-1 different pairs of integers “A B” telling you A will be knocked by B.

输出格式

The output should contain integers separated by spaces. Different courses should be separated by newlines (think of the sort order!).

样例

Input
4
3 1
2 1 3 2
5 1
2 2 3 3 4 4 5 1
7 1
2 1 3 1 4 1 5 1 6 1 7 1
7 4
2 1 3 1 4 1 5 1 6 1 7 1
Output
3
2 3 4
2 3 4 5 6 7
1 2 3 5 6 7

2 人解决,4 人已尝试。

2 份提交通过,共有 11 份提交。

9.2 EMB 奖励。

创建: 15 年,9 月前.

修改: 6 年,8 月前.

最后提交: 11 年前.

来源: Freshman Programming Contest

题目标签