CF1131F.Asya And Kittens

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Asya loves animals very much. Recently, she purchased nn kittens, enumerated them from 11 and nn and then put them into the cage. The cage consists of one row of nn cells, enumerated with integers from 11 to nn from left to right. Adjacent cells had a partially transparent partition wall between them, hence there were n1n - 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 ii , Asya:

  • Noticed, that the kittens xix_i and yiy_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 n1n - 1 days the cage contained a single cell, having all kittens.

For every day, Asya remembers numbers of kittens xix_i and yiy_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 nn cells.

输入格式

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

Each of the following n1n - 1 lines contains integers xix_i and yiy_i ( 1xi,yin1 \le x_i, y_i \le n , xiyix_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 xix_i and yiy_i were in the different cells before this day.

输出格式

For every cell from 11 to nn print a single integer — the index of the kitten from 11 to nn , 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.

输入输出样例

  • 输入#1

    5
    1 4
    2 5
    3 1
    4 5
    

    输出#1

    3 1 4 2 5
    

说明/提示

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.

首页