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

21114번 - Into Cactus 스페셜 저지다국어

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

문제

Given a tree, add as many edges as possible so that the resulting graph is a cactus graph.

A cactus graph is a graph where each edge is contained in at most one simple cycle. This graph may not contain self-loops or parallel edges.

입력

The first line contains an integer $N,ドル the size of the tree (1ドル \le N \le 200,000円$).

Each of the next $N - 1$ lines contains two integers $u$ and $v$ (1ドル \le u, v \le N,ドル $u \neq v$), indicating that there is an edge between nodes $u$ and $v$. It is guaranteed that the resulting graph is a tree.

출력

On the first line, output $K,ドル the maximum number of edges that can be added to the graph. On each of the next $K$ lines, output two integers $a$ and $b$ (1ドル \le a, b \le N,ドル $a \neq b$), indicating that you are going to add an edge between nodes $a$ and $b$. The resulting graph must be a cactus graph.

If there are several solutions with the maximum possible $K,ドル output any one of them.

제한

예제 입력 1

6
6 4
3 1
3 6
4 5
2 3

예제 출력 1

2
2 1
3 5

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2021 > Day 7: North American Contest 1 J번

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

출처

대학교 대회

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

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