PivotOJ

Two Choreographies

시간 제한: 2500ms메모리 제한: 1024MB출처: ICPC Asia Seoul Regional 2022BOJ 26113

문제

Somin and Eunjoo are famous dancers and very talented choreographers, but they haven't won a contest recently. To win the contest this year, they are trying to help each other to make new choreographies. Actually, nobody has tried smoothly appending static motions, and they are going to give it a try for the first time!

Somin and Eunjoo want to make two choreographies consisting of nn static motions for each of them. They have a good understanding of how to smoothly append static motions, and they concluded that exactly 2n32n - 3 unordered pairs of static motions are enough for them to perform freely. The order of static motions in a pair {A,B}\{A, B\} does not matter, i.e., if motion BB can be appended after motion AA, then AA can also be appended after BB.

The choreographies which Somin and Eunjoo want to perform are as follows. The two choreographies last for the same amount of time, which means that each one should consist of the same number of static motions. Each choreography should end at its first static motion. More precisely, two choreographies C1C_1 and C2C_2 are sequences of distinct ll static motions, C1=(a0,a1,,al)C_1 = (a_0, a_1, \dots , a_l) and C2=(b0,b1,,bl)C_2 = (b_0, b_1, \dots , b_l) where a0=ala_0 = a_l and b0=blb_0 = b_l. For the entertainment of the audience, C1C_1 and C2C_2 should be different, that is, there should be some 0 ≤ i ≤ l - 1 which {ai,ai+1}\{a_i, a_{i+1}\} in C1C_1 is not equal to any of {bj,bj+1}\{b_j, b_{j+1}\} in C2C_2 for 0 ≤ j ≤ l - 1. (For example, (1,2,3,4,5,1)(1,2,3,4,5,1) and (3,4,5,2,1,3)(3,4,5,2,1,3) are different but (1,2,3,4,5,1)(1,2,3,4,5,1) and (3,4,5,1,2,3)(3,4,5,1,2,3) are not.) Also, the audience easily gets bored, so the choreography should not be too short, and contain at least 33 distinct static motions, that is, l ≥ 3.

For this, you are given 2n32n - 3 unordered pairs PP of static motions from nn distinct static motions m1,,mnm_1, \dots, m_n that two dancers can perform. For a pair {mi,mj}\{m_i, m_j\} where i ≠ j, one of mim_i and mjm_j can appear after the other in the sequence; there is no specific order between them. You should write a program to find two different choreographies C1=(a0,a1,,al)C_1 = (a_0, a_1, \dots , a_l) and C2=(b0,b1,,bl)C_2 = (b_0, b_1, \dots , b_l) of the same length l ≥ 3 such that \{a_i, a_{i+1}\} ∈ P, \{b_i, b_{i+1}\} ∈ P for any 0 ≤ i ≤ l - 1, and a0=ala_0 = a_l and b0=blb_0 = b_l.

입력

Your program is to read from standard input. The input starts with a line containing a single integer, nn (4 ≤ n ≤ 100\,000), where nn is the number of static motions two dancers can represent. Each static motion is numbered as an integer from 11 to nn. The following 2n32n - 3 lines represent 2n32n - 3 unordered pairs of stack motions, PP. Each line contains two distinct integers representing two static motions of a pair of PP. Note that no two pairs in PP are identical.

출력

Your program is to write to standard output. If you cannot find two choreographies of static motions, then print 1-1. If not, you should print exactly three lines. The first line contains an integer l ≥ 3 which is the number of distinct static motions in each choreography. The second line contains exactly ll integers, separated by a space, each representing a choreography of the ll static motions in order. The last repeated motion should be omitted. The third line contains exactly ll integers representing the other choreography

예제

예제 1

입력
4
1 2
1 3
1 4
2 3
2 4
출력
3
1 2 3
1 2 4

예제 2

입력
5
1 2
1 3
1 4
1 5
2 3
2 5
3 4
출력
3
1 2 3
1 3 4

예제 3

입력
7
1 2
3 4
5 6
5 2
3 1
6 1
4 2
4 5
2 6
3 6
1 5
출력
4
6 1 5 2
4 2 1 3
코드를 제출하려면 로그인하세요.