CF1095D.Circular Dance
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n kids, numbered from 1 to n , dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p1 , p2 , ..., pn (all these numbers are from 1 to n and are distinct, so p is a permutation). Let the next kid for a kid pi be kid pi+1 if i<n and p1 otherwise. After the dance, each kid remembered two kids: the next kid (let's call him x ) and the next kid for x . Each kid told you which kids he/she remembered: the kid i remembered kids ai,1 and ai,2 . However, the order of ai,1 and ai,2 can differ from their order in the circle.
Example: 5 kids in a circle, p=[3,2,4,1,5] (or any cyclic shift). The information kids remembered is: a1,1=3 , a1,2=5 ; a2,1=1 , a2,2=4 ; a3,1=2 , a3,2=4 ; a4,1=1 , a4,2=5 ; a5,1=2 , a5,2=3 .You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
输入格式
The first line of the input contains one integer n ( 3≤n≤2⋅105 ) — the number of the kids.
The next n lines contain 2 integers each. The i -th line contains two integers ai,1 and ai,2 ( 1≤ai,1,ai,2≤n,ai,1=ai,2 ) — the kids the i -th kid remembered, given in arbitrary order.
输出格式
Print n integers p1 , p2 , ..., pn — permutation of integers from 1 to n , which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists.
输入输出样例
输入#1
5 3 5 1 4 2 4 1 5 2 3
输出#1
3 2 4 1 5
输入#2
3 2 3 3 1 1 2
输出#2
3 1 2