QOJ.ac

QOJ

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

#6086. Journey

Statistics

The globetrotter Bajtosz has decided to embark on the longest journey of his life. His destination is the vast island of Kilobajtoria. On this island, there are $n$ cities, numbered from $1$ to $n$. The road network of Kilobajtoria allows travel from any city to any other city without backtracking, and there is always exactly one path between any two cities. Each road has the same length.

Bajtosz has decided to visit all the cities of Kilobajtoria, starting from city number 1. To ensure his journey does not end too quickly, Bajtosz has decided that as long as there are cities he has not yet visited, he will always travel to the unvisited city located farthest from his current location (he does not "visit" the cities he passes through on the way). If at any point there are multiple cities that he could choose according to this rule, he will choose the one with the largest number.

Bajtosz is impressed by the crazy travel plan he has come up with. To avoid getting lost on the route and accidentally shortening his journey, he decided to write down the order of the cities he will visit in advance. However, he found this difficult, so he asked you for help.

Input

The first line of input contains a single integer $n$ ($1 \le n \le 500\,000$) representing the number of cities in Kilobajtoria. The next $n-1$ lines describe the individual roads. Each of these lines contains two integers $a_i, b_i$ ($1 \le a_i, b_i \le n$, $a_i \ne b_i$), indicating that cities $a_i$ and $b_i$ are connected by a two-way road.

Output

In the only line of output, print a permutation of numbers from $1$ to $n$ — the order in which Bajtosz will visit the cities of Kilobajtoria.

Examples

Input 1

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

Output 1

1 7 4 6 3 5 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.