A12398 | Asya And Kittens
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
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.

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.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted