邮票AI (CI翻译)
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.
一天,Bob 收到了一封装在信封里的信。Bob 知道,在 Berland,邮政工作人员直接将信件从城市 «A» 寄往城市 «B» 时,会在信上盖上 «A B» 或 «B A» 的邮戳。不幸的是,寄件人所在的城市和收件人所在的城市之间往往无法直接寄送信件,因此信件需要经过一些中间城市。邮政工作人员绝不会选择一条经过同一座城市多次的路线。Bob 确信邮政工作人员盖的邮戳都是准确的。AI (CI翻译)
There are $*n*$ stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.
Bob 的信封上有 $*n*$ 个邮戳。他知道这封信可能经过的路线只有两条,但邮戳太多了,他无法自行判断是哪一条。因此,他请你帮忙找出其中一条可能的路线。AI (CI翻译)
Input
输入格式
AI (CI翻译)The first line contains integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — amount of mail stamps on the envelope. Then there follow $*n*$ lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from $1$ to $10^{9}$. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city.
第一行包含一个整数 $*n*$($1 ≤ *n* ≤ 10^{5}$),表示信封上的邮戳数量。接下来 $*n*$ 行,每行包含两个整数,描述一个邮戳。每个邮戳由信件寄送的两个城市的编号表示。城市编号为 $1$ 到 $10^{9}$ 之间的整数,且所有城市的编号互不相同。每当信件从一座城市寄往另一座城市时,信封上恰好会盖一个邮戳。保证给定的邮戳对应于一条从某座城市到另一座不同城市的有效路线。AI (CI翻译)
Output
输出格式
AI (CI翻译)Output $*n* + 1$ numbers — indexes of cities in one of the two possible routes of the letter.
输出 $*n* + 1$ 个数字,表示这封信可能经过的路线上的城市编号。AI (CI翻译)
样例
2
1 100
100 2
2 100 1
3
3 1
100 2
3 2
100 2 3 1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。