#P15416. 「yrOI R1」夏日已逝
「yrOI R1」夏日已逝
Background

Problem Description
You are given two trees of size . Define one operation on as follows:
- Choose any diameter of .
- Choose any node on this diameter, then choose a node adjacent to that is not on this diameter, then choose another node on this diameter, and perform:
- Delete the edge , and add the edge .
You need to determine whether it is possible to apply the operation any number of times to transform into some , such that is isomorphic to . If it is possible, you need to output one valid plan within operations.
Input Format
The first line contains a positive integer , which is the size of trees and .
The next lines each contain two integers , representing an edge of tree .
The next lines each contain two integers , representing an edge of tree .
Output Format
Output a string or on the first line, indicating whether it is possible to make isomorphic to using the operations.
If you output , then on the next line output an integer , the number of operations in your constructed plan.
You must ensure that the number of operations is at most . If your number of operations exceeds , you will be judged as Wrong Answer.
In the next lines, output five integers , describing one operation.
Then you need to output one line , meaning that in the tree after all operations, node corresponds to node in tree .
This problem uses a Special Judge. If you correctly output or , you will get of the score for that subtask. Note: if you output , you must output a plan afterwards (even if it may be invalid; you can directly output zeros to do this).
7
1 2
2 3
3 7
3 4
4 5
5 6
7 6
6 5
5 4
4 3
3 2
3 1
Yes
1
1 6 3 7 5
7 6 5 4 3 2 1
4
1 2
2 3
3 4
1 2
1 3
1 4
No
Hint
This problem uses bundled testdata.
- Subtask 1 (5 pts): .
- Subtask 2 (5 pts): is a path.
- Subtask 3 (5 pts): is a path.
- Subtask 4 (5 pts): is a star (also called "juhua", 菊花).
- Subtask 5 (10 pts): and each have only one diameter, and all nodes with degree exist only on the diameter.
- Subtask 6 (10 pts): The initial diameters of and have the same length.
- Subtask 7 (25 pts): .
- Subtask 8 (35 pts): No special constraints.
For of the data, .
When all journeys end, and I fall into sleep.
I will surely return to this summer.
Translated by ChatGPT 5