QOJ.ac

QOJ

Time Limit: 4.0 s Memory Limit: 256 MB Total points: 100

#6086. Podróż

الإحصائيات

环游世界的巴伊托什决定踏上他一生中最长的一次旅程。他将旅行的目的地定为广袤的千巴伊托西亚岛。在这座岛上有 $n$ 座城市,编号从 $1$ 到 $n$。千巴伊托西亚的道路网络允许从任意一座城市前往另一座城市而无需折返,而且总是只有唯一一条路径可达。每条道路的长度都是相同的。

巴伊托什决定从编号为 1 的城市开始,游览千巴伊托西亚的所有城市。为了避免旅程太快结束,他决定:只要还有他尚未游览过的城市,他总会前往距离他当前位置最远的未游览城市(途经的城市不算作已游览)。如果在某个时刻有多座城市符合这个条件,他将选择编号最大的那一座。

巴伊托什对自己想出的这个疯狂旅行计划感到惊叹。为了在途中不迷路或不小心缩短了旅程,他决定提前记录下城市的游览顺序。然而这让他感到有些困难,因此他请求你帮忙。

输入格式

输入的第一行包含一个整数 $n$($1 \le n \le 500,000$),表示千巴伊托西亚的城市数量。接下来的 $n-1$ 行描述了各条道路。每一行包含两个整数 $a_i, b_i$($1 \le a_i, b_i \le n$, $a_i \ne b_i$),表示城市 $a_i$ 和 $b_i$ 之间有一条双向道路相连。

输出格式

输出的唯一一行应为从 $1$ 到 $n$ 的一个排列,表示巴伊托什游览千巴伊托西亚城市的顺序。

示例

输入

7
1 2
2 3
2 4
5 1
6 5
7 5

输出

1 7 4 6 3 5 2
problem_6086_1.gif?v
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.