Queue

题意翻译

有n个学生排成一列,每个学生都记下了直接站在他前面和后面的学生的学生证号码(如果是第一个前面是0,最后一个后面是0),现在让你帮助学生通过队列中相邻的学生ID号码恢复队列状态。 输入:第一行:学生数量n;接下来n行,每行两个数,分别为每个学生前后两个学生的ID号码 输出:为恢复后的队列 Translated by 皇家海盗

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #1

4
92 31
0 7
31 0
7 141

输出样例 #1

92 7 31 141 

说明

The picture illustrates the queue for the first sample. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF490B/08daf79334436a27cb8cf554f27be1c975002c35.png)