Into Cactus
시간 제한1초메모리 제한512 MB
N개 노드로 이루어진 트리가 주어질 때, 어떤 간선도 두 개 이상의 단순 사이클에 속하지 않도록 간선을 최대한 많이 추가하고, 추가한 간선들을 출력한다.
문제
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 , the size of the tree ().
Each of the next lines contains two integers and (, ), indicating that there is an edge between nodes and . It is guaranteed that the resulting graph is a tree.
출력
On the first line, output , the maximum number of edges that can be added to the graph. On each of the next lines, output two integers and (, ), indicating that you are going to add an edge between nodes and . The resulting graph must be a cactus graph.
If there are several solutions with the maximum possible , output any one of them.