#P14733. [ICPC 2022 Seoul R] Two Choreographies

[ICPC 2022 Seoul R] Two Choreographies

题目描述

Somim 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!

Somim 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 Somim 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, ..., a_l) and C2=(b0,b1,...,bl)C_2 = (b_0, b_1, ..., 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 0il10 \leq i \leq 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 0jl10 \leq j \leq 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 3 distinct static motions, that is, l3l \geq 3.

For this, you are given 2n32n - 3 unordered pairs PP of static motions from nn distinct static motions m1,...,mnm_1, ..., m_n that two dancers can perform. For a pair {mi,mj}\{m_i, m_j\} where iji \neq 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, ..., a_l) and C2=(b0,b1,...,bl)C_2 = (b_0, b_1, ..., b_l) of the same length l3l \geq 3 such that {ai,ai+1}P\{a_i, a_{i+1}\} \in P, {bi,bi+1}P\{b_i, b_{i+1}\} \in P for any 0il10 \leq i \leq 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 (4n100,0004 \leq n \leq 100,000), where nn is the number of static motions two dancers can represent. Each static motion is numbered as an integer from 1 to nn. The following 2n32n - 3 lines represent 2n32n - 3 unordered pairs of static 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 l3l \geq 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.

4
1 2
1 3
1 4
2 3
2 4
3
1 2 3
1 2 4
5
1 2
1 3
1 4
1 5
2 3
2 5
3 4
3
1 2 3
1 3 4
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