欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1131F.Asya And Kittens
Asya And Kittens
Asya loves animals very much. Recently, she purchased kittens, enumerated them from and and then put them into the cage. The cage consists of one row of cells, enumerated with integers from to from left to right. Adjacent cells had a partially transparent partition wall between them, hence there were 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 , Asya:
- Noticed, that the kittens and , 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 days the cage contained a single cell, having all kittens.
For every day, Asya remembers numbers of kittens and , 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 cells.
Input
The first line contains a single integer () — the number of kittens.
Each of the following lines contains integers and (, ) — indices of kittens, which got together due to the border removal on the corresponding day.
It's guaranteed, that the kittens and were in the different cells before this day.
Output
For every cell from to print a single integer — the index of the kitten from to , 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.

Samples
5
1 4
2 5
3 1
4 5
3 1 4 2 5
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |