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

30292번 - Simple Link Cut Problem 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB111181628.571%

문제

You are given a tree with $N$ vertices. You can repeat the following operation at most 10ドル^5$ times.

  • Choose four distinct vertices $v_1, v_2, v_3, v_4$ such that there exist edges between $v_1$ and $v_2,ドル $v_2$ and $v_3,ドル $v_3$ and $v_4$. Remove these edges and add edges between $v_1$ and $v_3,ドル $v_1$ and $v_4,ドル $v_2$ and $v_4$.

Your task is transform the given tree so that its diameter is at most 3ドル$. Find a sequence of operations that does so.

입력

The first line contains one integer $N$.

The $i$-th of the following $N-1$ lines contains space-separated two integers $x_i$ and $y_i,ドル meaning that the $i$-th edge connects vertices $x_i$ and $y_i$ in the tree.

출력

At the first line, print $K,ドル the number of operations.

In the next $K$ line, print four integers $v_1,ドル $v_2,ドル $v_3,ドル $v_4$ separated by space.

If there are multiple solutions, print any. It can be proven that there exists at least one way to achieve the goal.

Note that you do not have to minimize $K$.

제한

  • 4ドル \leq N \leq 100$
  • 1ドル \le x_i, y_i \le N$; $x_i \neq y_i$ $(1 \le i \le N-1)$
  • It is guaranteed that the given edges form a tree.
  • 0ドル \leq K \leq 100,000$
  • $v_1, v_2, v_3, v_4$ should satisfy the conditions of the given operation.

예제 입력 1

6
1 2
2 3
3 4
4 5
5 6

예제 출력 1

3
4 3 2 1
6 5 4 1
2 4 6 1

노트

The distance between two vertices $u$ and $v$ is defined as the number of the edges of the unique path from $u$ to $v$.

The diameter of a tree is the maximum distance between any two vertices.

출처

University > KAIST > KAIST ICPC Mock Competition > 2023 KAIST 13th ICPC Mock Competition A번

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 2: K-ontest A번

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

출처

대학교 대회

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

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