#P2092. Tree Transform
Tree Transform
题目描述
点击这里查看pdf
MianKing has two labeled unrooted trees , with nodes and he wants to transform to by some operations.
In each operation, MianKing can select four distinct nodes which forms a path in the tree . Then he removes edges from , chooses three new edges whose endpoints and adds these new edges to . MianKing has to guarantee that is still a tree after this operation.
Now you need to help MianKing to transform to within operations.
输入格式
The first line has one integer .
Then there are lines, each lines has two integers which denotes an edge in .
Then there are lines, each lines has two integers which denotes an edge in .
It's guaranteed that and are both trees.
输出格式
The first line has one string "YES" if there exists a solution to transform to within operations, otherwise "NO". (both without quotation)
If there exists a solution, then:
The first line has one integers which denotes the number of operations of your solution.
Then for each operations, there are two lines which represent this operations. The first line has four integers and the second line has six integers which denotes the i-th new edge you choose in this operation.
For each operation, you should guarantee these conditions:
-
-
are distinct and form a path in the tree at that time.
-
-
After removing edges and add new edges , is still a tree at that time.
-
After all of the operations, should be the same as .
-
Two labeled tree are same if and only if for all edge
样例
5
1 2
2 3
3 4
2 5
1 2
2 3
3 4
1 5
YES
2
5 2 3 4
2 3 3 5 3 4
1 2 3 5
1 5 1 2 2 3
4
1 2
1 3
1 4
1 2
2 3
3 4
NO
4
1 2
1 3
1 4
1 2
1 3
1 4
YES
0
提示
Form 2020ICPC济南站