Lost Purity
InterviewTime limit1sMemory limit1024 MB
Given a tree, add the fewest edges so that every vertex lies on a cycle, then print the endpoints of each added edge.
Problem
There is a tree with vertices and edges. The vertices are numbered . Add the fewest possible edges to this tree so that every vertex lies on at least one cycle. An edge cannot connect a vertex to itself, and the completed graph can have at most one edge between any two vertices.
Find the minimum number of edges to add, and the two endpoints of each added edge.
Input
The first line contains an integer ().
Each of the next lines contains two integers (), the endpoints of an edge, separated by a space.
Output
On the first line, print the minimum number of edges to add.
On each of the next lines, print the two endpoints () of an added edge, separated by a space.
If there are multiple valid answers, print any one of them.