#3078. Chocolate Milk

Chocolate Milk

Background

USACO Silver

Description

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.)

FJ的牛奶生产和运输是一个复杂的过程,他用挤奶器给他的那么多头奶牛挤奶然后流入管道。 每一个管道把一台挤奶器和一个可能连有一台或多台挤奶器的接口连接起来(这样几个管道里的牛奶就汇合了)。然后牛奶流入附加管道(连在各个接口之间的管道)直到流到中央管道,通向储存室。 然后这些牛奶又经历一个逆向的过程通过管道分流到各个牛奶桶,最后被运至市场。 FJ发现对于牛奶来说有一种最多的方式从一个接口流到另一个接口。并且由于FJ是一个高效率的人,他需要确保每一个管道都有牛奶经过,也就是说,没有多余的管道。

如果我们把每个挤奶机、接口和奶罐都看成一个节点,就共有 N 个节点,输入有序的节点对A_i和B_i,代表牛奶从A_i节点流到B_i节点,如果没有相对应的父节点,那就说明这是一个挤奶器,同样的如果没有对应的尾节点,则这是一个奶罐。

FJ把这些节点编号为 1..N,这样表示牛奶只能从编号较小节点流到编号较大节点。也就是说有N-1个管道。

这几天巧克力牛奶的需求量激增,所以FJ想要在某一个接口处安装一个巧克力混合器以得到巧克力牛奶,为了节约,FJ只买了一个巧克力混合器。所以他想把这个东西放到一个所有牛奶都能经过的接口,事实上,有这种接口存在。

编程帮助FJ找到这样的节点(注意:不能把巧克力混合器放在挤奶机里)。 例如:这样的情况:

image

一看就知道,在6或者7可以装巧克力混合器。

Format

Input

第一行:一个整数N; 第2..N行 :第i+1行用两个整数A_i 和 B_i,表示第i个管道的两端;

Output

若干行,升序输出每一个可以安装混合器的节点。

Samples

9
1 4
3 5
2 4
5 6
6 7
7 8
4 6
7 9
6
7

Limitation

【数据规模】 对于40%的数据: 2≤N≤250; 对于50%的数据: 2≤N≤6,000; 对于100%的数据:2≤N≤100,000;1≤A_i<B_i≤N;