Simple Link Cut Problem
시간 제한1초메모리 제한1024 MB
트리에 경로 회전 연산을 반복해 지름이 3 이하가 되도록 만들고, 사용한 연산 순서를 출력한다.
문제
You are given a tree with vertices. You can repeat the following operation at most times.
- Choose four distinct vertices such that there exist edges between and , and , and . Remove these edges and add edges between and , and , and .
Your task is transform the given tree so that its diameter is at most . Find a sequence of operations that does so.
입력
The first line contains one integer .
The -th of the following lines contains space-separated two integers and , meaning that the -th edge connects vertices and in the tree.
출력
At the first line, print , the number of operations.
In the next line, print four integers , , , 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 .
제한
- ;
- It is guaranteed that the given edges form a tree.
- should satisfy the conditions of the given operation.
힌트
The distance between two vertices and is defined as the number of the edges of the unique path from to .
The diameter of a tree is the maximum distance between any two vertices.