题目描述
Farmer John's milk production and shipping system is an intricate one! He uses milking machines for his many cows to harvest the milk that then flows into pipes.
Each of these pipes connects a milking machine to a joint, where it might be joined by exactly one more pipe (the milk flowing through both pipes merges). The milk then flows through additional pipes (which all start and end at joints) until it reaches the long central pipe connecting to the distribution room.
The milk then goes through a reverse process of splitting at various joints until it is flows into milk tanks that are picked up and taken to market.
Farmer John notices that there is at most one way for milk to travel from one joint to any other joint. Furthermore, since Farmer John is an efficient man by nature, he has made sure that milk will flow through each and every pipe; in other words, no pipe is unneeded.
If we think of a milking machine, joint, or milk tank as a node, there are N (2 <= N <= 100,000) nodes in total (and N-1 pipes
connecting them). The input describes each pipe as an ordered pair of nodes, A_i (1 <= A_i <= N) and B_i (1 <= B_i <= N; A_i < B_i) indicating milk flows from node A_i to node B_i. If there is no pipe coming in to A_i, it is a milking machine. Likewise, if no pipe goes out from B_i, it is a tank.
The demand of chocolate milk has skyrocketed in recent months, and Farmer John wants to install a chocolate inserter at one of the joints so he can create delicious chocolate milk for customers.
Being thrifty, Farmer John has only bought one chocolate inserter, so he wants to place it at a joint through which all the milk passes. He knows that such a joint exists.
Help Farmer John find all the possible places he can install the chocolate inserter. (Note that Farmer John cannot install the chocolate inserter at the same location as a milking machine.)
As an example, consider a milking setup like this one:
1 ----+
|
v
2 --> 4 --> 6 ------------------> 7 --> 8
^ |
| |
3 --> 5 ----+ + --> 9
Visual inspection shows that the chocolate inserter can be installed at either joint 6 or 7, as all milk flows through those joints.
农民约翰的牛奶生产和运输系统是极其复杂的!他用挤奶机为他的许多奶牛收获牛奶,然后流入管道。
每一个管道连接挤奶机到一个节点,在那里它可能会加入一个管道(牛奶流过两个管道合并)。然后,牛奶流通过额外的管道(所有的开始点和结束点在其它节点上的),直到它到达一个关键的节点。
牛奶然后经过一个反向的过程,在不同的关节分裂,直到它流入牛奶罐被拾起,并送往市场。
农场主约翰注意到,牛奶从一个关节到另一个关节的方式最多。此外,由于农民约翰本质上是一个能干的人,他已经确信,牛奶会流通过每个管道;换句话说,没有管道是不必要的。
如果我们认为挤奶机,节点,或牛奶罐都看作一个节点,有N (2 <= N <= 100,000)节点总数(N-1个管道连接它们)。
输入描述每个管节点的有序对,A_i(1 <= A_i <= N)和B_i(1 <= B_i <= N;A_i < B_i)表示牛奶从A_i流向B_i。如果A_i入度为0,它是一个挤奶机。同样,B_i出度为0,它是一个牛奶罐。
巧克力牛奶的需求已经在最近几个月急剧增加,农民约翰想安装一个巧克力插件在一个节点上,保证他能为顾客创造美味的巧克力牛奶。
为了节俭,农民约翰只买了一个巧克力插件,所以他想把它安在一个牛奶都经过的节点上。他知道这样的节点存在。
帮助农民约翰找到所有可能的地方,他将在那儿安装巧克力的插件。(注:农民约翰巧克力插件不能安装在一个挤奶机上。)
1 ----+
|
v
2 --> 4 --> 6 ------------------> 7 --> 8
^ |
| |
3 --> 5 ----+ + --> 9
巧克力插件可以安装在6或7上,所有牛奶流经这些节点。
输入格式:
Line 1: A single integer: N
Lines 2..N: Line i+1 contains two space-separated integers that describe a pipe's connectivity: A_i and B_i
第1行:一个整数:N
2到N行:包含空格分隔的两个整数描述管道的连接:A_i和B_i
输出格式:
Lines 1..??: Integers, one per line and in ascending order, each denoting a possible joint at which to install the chocolate inserter.
第1行到??行:每行一个整数,升序排列,每个表示可以安装巧克力插件的节点。
输入样例#1:
9
1 4
3 5
2 4
5 6
6 7
7 8
4 6
7 9
输出样例#1:
6
7