Hide

Problem B
BrIllIance of Wings

Mashiro has a tree with $N$ vertices and $N - 1$ unweighted edges. It is known that any two vertices in the tree are connected.

Mashiro wants to perform a Morfonication on the tree. To put it simply, Mashiro will do several operations to transform the original tree to a new tree to her liking. Each operation Mashiro does is of the following:

  • Select an edge from the tree and remove it. After this step, the tree becomes disconnected to two components.

  • Add an edge between any two vertices such that the structure is reconnected into a tree.

After every operation Mashiro does, the tree must stay as a tree, meaning it must have exactly $N - 1$ edges and any two vertices in the tree are connected.

Mashiro has came back from practice and she wants to know the exact operations of the Morfonication. Can you show her the operations to do so in the least number of operations possible?

Input

The first line of input contains one integer $N$ $(2 \leq N \leq 10^5)$, the size of the two trees.

The second to $N$-th lines of the input contain two integers $U_i$ and $V_i$ $(1 \leq U_i, V_i \leq N, U_i \ne V_i)$, the edges of the first tree.

The $(N+1)$-th to $(2N - 1)$-th lines of the input contains two integers $X_i$ and $Y_i$ $(1 \leq X_i, Y_i \leq N, X_i \ne Y_i)$, the edges of the second tree.

Output

The first line of output contains one integer denoting the minimum number of operations, $K$.

The next $K$ lines contain four integers $A_i$, $B_i$, $C_i$, and $D_i$ $(1 \leq A_i, B_i, C_i, D_i \leq N, A_i \ne B_i, C_i \ne D_i)$ denoting an operation of removing edge $(A_i, B_i)$ and adding edge $(C_i, D_i)$. The operations should follow the rules given in the problem description, otherwise a Wrong Answer verdict is given.

If there are multiple possible answers, print any of them.

Sample Input 1 Sample Output 1
4
1 2
2 3
3 4
3 1
4 1
2 4
3
4 3 2 4
3 2 1 3
2 1 1 4

Please log in to submit a solution to this problem

Log in