Codeforces Round 541 (Div. 2)
F
Asya And Kittens
Codeforces
1700
原题
← EG →
翻译中…

Asya loves animals very much. Recently, she purchased $n$ kittens, enumerated them from $1$ and $n$ and then put them into the cage. The cage consists of one row of $n$ cells, enumerated with integers from $1$ to $n$ from left to right. Adjacent cells had a partially transparent partition wall between them, hence there were $n - 1$ partitions originally. Initially, each cell contained exactly one kitten with some number.

翻译中…

Observing the kittens, Asya noticed, that they are very friendly and often a pair of kittens in neighboring cells wants to play together. So Asya started to remove partitions between neighboring cells. In particular, on the day $i$, Asya:

翻译中…
  • Noticed, that the kittens $x_i$ and $y_i$, located in neighboring cells want to play together.
  • Removed the partition between these two cells, efficiently creating a single cell, having all kittens from two original cells.
翻译中…

Since Asya has never putted partitions back, after $n - 1$ days the cage contained a single cell, having all kittens.

翻译中…

For every day, Asya remembers numbers of kittens $x_i$ and $y_i$, who wanted to play together, however she doesn't remember how she placed kittens in the cage in the beginning. Please help her and find any possible initial arrangement of the kittens into $n$ cells.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of kittens.

翻译中…

Each of the following $n - 1$ lines contains integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$) — indices of kittens, which got together due to the border removal on the corresponding day.

翻译中…

It's guaranteed, that the kittens $x_i$ and $y_i$ were in the different cells before this day.

翻译中…

Output

翻译中…

For every cell from $1$ to $n$ print a single integer — the index of the kitten from $1$ to $n$, who was originally in it.

翻译中…

All printed integers must be distinct.

翻译中…

It's guaranteed, that there is at least one answer possible. In case there are multiple possible answers, print any of them.

翻译中…

Note

翻译中…

The answer for the example contains one of several possible initial arrangements of the kittens.

翻译中…

The picture below shows how the cells were united for this initial arrangement. Note, that the kittens who wanted to play together on each day were indeed in adjacent cells.

翻译中…

image

翻译中…

样例

Input #1
5
1 4
2 5
3 1
4 5
Output #1
3 1 4 2 5
InputCopy OutputCopy
题目信息
题号
1131F
时间限制
2 s
内存限制
256 MB
标签
构造
并查集

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。