#P1906I. Contingency Plan 2
Contingency Plan 2
No submission language available for this problem.
Description
You are working as a manager in The ICPC Company. In the company building, there are computers (numbered from to ). There are cables, numbered from to , that connect all the computers into a single network. Cable connects computer and . Each cable can be set into emergency mode, where cable only transfers data from computer to computer , but not the other way around. During a disaster, it is mandatory for all cables to be in emergency mode.
Through your research, you discover a new way to determine the vulnerability of a network. You want to add zero or more new cables to the current network such that it is not vulnerable during a disaster. Your network is not vulnerable if and only if there is exactly one permutation of to such that appears before in the permutation for all cables that connect computer and . In other words, it should have exactly one topological order.
The following illustration shows examples of not vulnerable networks and vulnerable networks.

For the not vulnerable networks, the only permutation that satisfies the requirement for the networks on the left and on the right are and , respectively. Meanwhile, for the vulnerable networks, there are permutations that satisfy the requirement for the network on the left: and ; while there is no permutation that satisfies the requirement for the network on the right.
You are interested in the minimum number of new cables that should be added to the current network such that it is not vulnerable during a disaster. Furthermore, you want to know, which pairs of computers should be connected by using the minimum number of cables. If there are several ways to connect, you can connect in any way of your choice. Under the given constraints, it can be proven that there exists a way to make the network not vulnerable.
The first line consists of an integer ().
Each of the next lines consists of two integers (). The input edges form a tree.
The first line consists of an integer, representing the minimum number of new cables that should be added to the current network such that it is no longer vulnerable during a disaster. Denote this number as and the new cables are numbered from to .
If is not , then output lines. Each of the next lines consists of two integers , representing the computers that are connected by the new cable . During a disaster, new cable only transfers data from computer to computer , but not the other way around. If there exist several solutions, you can output any of them.
Input
The first line consists of an integer ().
Each of the next lines consists of two integers (). The input edges form a tree.
Output
The first line consists of an integer, representing the minimum number of new cables that should be added to the current network such that it is no longer vulnerable during a disaster. Denote this number as and the new cables are numbered from to .
If is not , then output lines. Each of the next lines consists of two integers , representing the computers that are connected by the new cable . During a disaster, new cable only transfers data from computer to computer , but not the other way around. If there exist several solutions, you can output any of them.
Note
Explanation for the sample input/output #3
The following illustration shows the original network and the new network with the added cables during a disaster. The only permutation that satisfies the requirement is .
