CF1095D.Circular Dance

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn kids, numbered from 11 to nn , dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p1p_1 , p2p_2 , ..., pnp_n (all these numbers are from 11 to nn and are distinct, so pp is a permutation). Let the next kid for a kid pip_i be kid pi+1p_{i + 1} if i<ni < n and p1p_1 otherwise. After the dance, each kid remembered two kids: the next kid (let's call him xx ) and the next kid for xx . Each kid told you which kids he/she remembered: the kid ii remembered kids ai,1a_{i, 1} and ai,2a_{i, 2} . However, the order of ai,1a_{i, 1} and ai,2a_{i, 2} can differ from their order in the circle.

Example: 5 kids in a circle, p=[3,2,4,1,5]p=[3, 2, 4, 1, 5] (or any cyclic shift). The information kids remembered is: a1,1=3a_{1,1}=3 , a1,2=5a_{1,2}=5 ; a2,1=1a_{2,1}=1 , a2,2=4a_{2,2}=4 ; a3,1=2a_{3,1}=2 , a3,2=4a_{3,2}=4 ; a4,1=1a_{4,1}=1 , a4,2=5a_{4,2}=5 ; a5,1=2a_{5,1}=2 , a5,2=3a_{5,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 nn ( 3n21053 \le n \le 2 \cdot 10^5 ) — the number of the kids.

The next nn lines contain 22 integers each. The ii -th line contains two integers ai,1a_{i, 1} and ai,2a_{i, 2} ( 1ai,1,ai,2n,ai,1ai,21 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2} ) — the kids the ii -th kid remembered, given in arbitrary order.

输出格式

Print nn integers p1p_1 , p2p_2 , ..., pnp_n — permutation of integers from 11 to nn , 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 
    
首页