Logo
(追記) (追記ここまで)

21628번 - Perfect Round Dance 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB22229.091%

문제

The kindergarten founded by Finley Marlin is attended by exactly 2ドルn$ children. Today they have a party and the kids will dance around the large palm tree in the center of the room. There are young kids involved, so there are some restrictions on how the event would be organized.

For example, every kid has the best friend, and every kid is also the best friend of his best friend. If we consider pairs of best friends, they will be kids with numbers 2ドルi - 1$ and 2ドルi$. Kids refuses to participate in the dance if they are not standing next to their best friend.

The kid number $i$ came to the party wearing outfit $x_i,ドル but there can be some identical outfits worn by different children. So if two kids are not best friends and they wear the same outfits, they refuse to stand next to each other. Friendship is stronger than fashion, so best friends agree to stand next to each other even if they wear the same outfit.

Please help the tired teachers to place as much children as possible into the circle so that all the demands of children standing in circle are satisfied.

입력

The first line of input contains one integer $n$ --- the number of pairs of children (1ドル \leq n \leq 300,000円$).

Each of the following $n$ lines contains two integers: the $i$-th line contains $x_{2i-1}$ and $x_{2i}$ --- the outfits worn by the $(2i-1)$-th and the 2ドルi$-th kids respectively (1ドル \leq x_{2i-1}, x_{2i} \leq 2n$).

출력

The first line of output must contain $k$ --- the maximum number of pairs of children that can form the circle. Even one pair can form a circle.

The next line should contain space-separated numbers of children in the circle in the order they are standing.

If there are several optimal answers output any of them.

제한

예제 입력 1

3
1 1
1 2
1 3

예제 출력 1

2
3 4 5 6

예제 입력 2

4
1 2
3 4
4 2
1 3

예제 출력 2

4
1 2 3 4 6 5 7 8

힌트

출처

Olympiad > Russian Olympiad in Informatics > Russia High School Programming Contest > Russia High School Programming Contest 2020 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /