CF29C.Mail Stamps

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.

一天,鲍勃收到了一封装在信封里的信。鲍勃知道,当贝尔兰的邮局工作人员将一封信直接从城市「A」寄往城市「B」时,会在信封上盖上「A B」或「B A」的邮戳。不幸的是,常常无法直接从发信城市寄到收信城市,因此信件需经由若干中间城市中转。邮局工作人员绝不会以某种方式寄送信件,使得该信件的路径中某个城市出现超过一次。鲍勃确信邮局工作人员盖邮戳是准确无误的。

鲍勃的信封上有 nn 个邮戳。他意识到这封信可能的路径仅有两条。但由于邮戳数量众多,鲍勃自己无法确定其中任意一条路径。因此,他请你帮忙:找出该信件的一条可能路径。

输入格式

The first line contains integer n (1 ≤ n ≤ 105) — 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 109. 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.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——信封上的邮票数量。接下来有 nn 行,每行包含两个整数,用于描述一枚邮票。每枚邮票通过其所连接的两座城市的编号来描述。城市的编号为 11 到 10910^9 之间的整数,且所有城市的编号互不相同。每次信件从一座城市寄往另一座城市时,信封上恰好贴一枚邮票。保证所给邮票对应某条从某座城市到另一座城市的合法路径。

输出格式

Output n + 1 numbers — indexes of cities in one of the two possible routes of the letter.

输出 n+1n+1 个数——信件在两种可能路线之一中所经过的城市索引。

输入输出样例

  • 输入#1

    2
    1 100
    100 2

    输出#1

    2 100 1
  • 输入#2

    3
    3 1
    100 2
    3 2

    输出#2

    100 2 3 1

输入解题思路,AI测评打分。不知道怎么写?

首页