Codeforces Round 279 (Div. 2)
B
Queue
Codeforces
1500
原题
← AC →
翻译中…

During the lunch break all $*n*$ Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.

翻译中…

Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from $1$).

翻译中…

After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.

翻译中…

Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($2 ≤ *n* ≤ 2·10^{5}$) — the number of students in the queue.

翻译中…

Then $*n*$ lines follow, $*i*$-th line contains the pair of integers $*a*_{*i*}, *b*_{*i*}$ ($0 ≤ *a*_{*i*}, *b*_{*i*} ≤ 10^{6}$), where $*a*_{*i*}$ is the ID number of a person in front of a student and $*b*_{*i*}$ is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.

翻译中…

The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.

翻译中…

Output

翻译中…

Print a sequence of $*n*$ integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$ — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.

翻译中…

Note

翻译中…

The picture illustrates the queue for the first sample.

翻译中…

image

翻译中…

样例

Input #1
4
92 31
0 7
31 0
7 141
Output #1
92 7 31 141
InputCopy OutputCopy
题目信息
题号
490B
时间限制
2 s
内存限制
256 MB
标签
并查集
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。