New Year and Social Network

같은 n개 정점 위의 두 신장 트리 T1, T2가 주어질 때, T1의 간선들을 서로 다른 T2의 간선으로 교체해도 트리가 유지되도록 하는 최대 매칭을 찾아 그 쌍들을 출력한다.

어려움9그래프유니온 파인드그리디트리아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

Donghyun's new social network service (SNS) contains nn users numbered 1,2,,n1, 2, \ldots, n. Internally, their network is a \textit{tree graph}, so there are n1n-1 direct connections between each user. Each user can reach every other users by using some sequence of direct connections. From now on, we will denote this primary network as T_1T\_1.

To prevent a possible server breakdown, Donghyun created a backup network T_2T\_2, which also connects the same nn users via a tree graph. If a system breaks down, exactly one edge eT_1e \in T\_1 becomes unusable. In this case, Donghyun will protect the edge ee by picking another edge fT_2f \in T\_2, and add it to the existing network. This new edge should make the network be connected again. 

Donghyun wants to assign a replacement edge fT_2f \in T\_2 for as many edges eT_1e \in T\_1 as possible. However, since the backup network T_2T\_2 is fragile, fT_2f \in T\_2 can be assigned as the replacement edge for at most one edge in T_1T\_1. With this restriction, Donghyun wants to protect as many edges in T_1T\_1 as possible.

Formally, let E(T)E(T) be an edge set of the tree TT. We consider a bipartite graph with two parts E(T_1)E(T\_1) and E(T_2)E(T\_2). For eE(T_1),fE(T_2)e \in E(T\_1), f \in E(T\_2), there is an edge connecting e,f\\{e, f\\} if and only if graph T_1e+fT\_1 - \\{e\\} + \\{f\\} is a tree. You should find a maximum matching in this bipartite graph.

입력

The first line contains an integer nn (2n250,0002 \le n \le 250\\,000), the number of users. 

In the next n1n-1 lines, two integers a_ia\_i, b_ib\_i (1a_i,b_in1 \le a\_i, b\_i \le n) are given. Those two numbers denote the indices of the vertices connected by the corresponding edge in T_1T\_1.

In the next n1n-1 lines, two integers c_ic\_i, d_id\_i (1c_i,d_in1 \le c\_i, d\_i \le n) are given. Those two numbers denote the indices of the vertices connected by the corresponding edge in T_2T\_2

It is guaranteed that both edge sets form a tree of size nn.

출력

In the first line, print the number mm (0m<n0 \leq m < n), the maximum number of edges that can be protected.

In the next mm lines, print four integers a_i,b_i,c_i,d_ia\_i, b\_i, c\_i, d\_i. Those four numbers denote that the edge (a_i,b_i)(a\_i, b\_i) in T_1T\_1 is will be replaced with an edge (c_i,d_i)(c\_i, d\_i) in T_2T\_2.

All printed edges should belong to their respective network, and they should link to distinct edges in their respective network. If one removes an edge (a_i,b_i)(a\_i, b\_i) from T_1T\_1 and adds edge (c_i,d_i)(c\_i, d\_i) from T_2T\_2, the network should remain connected. The order of printing the edges or the order of vertices in each edge does not matter.

If there are several solutions, you can print any.