#P13343. [EGOI 2025] A String Problem
[EGOI 2025] A String Problem
题目描述
Lara loves flea markets. Last Saturday, there was the Rheinaue-Flohmarkt in Bonn, one of the biggest flea markets in Germany. Of course, Lara spent the whole day there, strolling through the market, haggling over prices, and buying all kinds of curious things. The most interesting thing she brought home was a small harp in a perfectly circular shape. When she wanted to start playing it, she noticed that the strings were all over the place rather than being parallel to each other.
More specifically, there are pins distributed evenly around the circular frame. Each of the strings is held in place by two of the pins, and every pin has exactly one string attached.
Lara does not know much about harps, but she strongly suspects that the strings should be aligned so that they are parallel to each other. To fix this issue, she decides to restring the harp. In each step, she can detach one end of a string from its pin and reattach it to a different pin. During the process it is okay if the ends of multiple strings are attached to the same pin. In the end, there should be exactly one string attached to every pin once again, and the strings should be parallel to each other.
Below you can find two examples of harps with parallel strings.
Since each step of restringing is a lot of work, Lara wants to restring the harp with as few steps as possible. Help Lara find a restringing sequence that takes the minimum number of steps!
输入格式
The first line of input contains one integer , denoting the number of strings. The strings are numbered from to .
Then follow lines, where the th line () contains two integers and , the two pins that hold the th string in place. The pins are numbered in clockwise order from to . Every pin has exactly one string attached.
输出格式
Output an integer , the minimum number of steps needed to restring the harp such that all strings are parallel to each other.
Further, output lines, each containing three integers , , and , denoting that in this step of your solution, one end of the th string should be detached from pin and reattached to pin (, ).
Note that if the th string is not attached to pin at that moment, the sequence of moves is considered to be incorrect.
If several answers exist, you may print any of them. Note that partially correct answers may still score some points, as explained in the next section.
5
1 5
4 9
6 3
2 7
0 8
3
4 8 9
0 5 8
1 9 5
5
0 1
3 2
4 5
6 7
9 8
4
1 3 9
4 9 3
2 5 7
3 7 5
4
1 4
6 3
5 2
7 0
2
0 4 6
1 6 4
6
3 9
7 5
10 2
0 6
1 11
8 4
6
3 6 1
4 1 2
2 2 3
0 3 4
5 4 5
1 5 6
提示
Examples
In the first sample, we are given a harp with five strings. In the first step, string is detached from pin and reattached to pin . In the next step, string is detached from pin and reattached to pin . In the last step, string is detached from pin and reattached to pin . Now, there is exactly one string attached to each pin, and all strings are parallel to each other. This sequence is shown in the figure below.
The figure below shows the initial state of the harp for samples 2, 3, and 4.
- The first sample satisfies the constraints of test groups 4 and 5.
- The second sample satisfies the constraints of test groups 1, 3, 4, and 5.
- The third sample satisfies the constraints of test groups 2, 4, and 5.
- The fourth sample satisfies the constraints of test groups 3, 4, and 5.
Constraints and Scoring
- .
- .
- All and are unique.
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. For each test group, your points are determined as follows:
- If your program solves all test cases in the test group, you get of the points.
- If your program does not fully solve the test group but it correctly outputs the minimum number of steps for each of them, you get of the points.
When determining whether your solution scores of the points for a test group, only the value it outputs is judged. The solution can just output the value and terminate, or it can even output an invalid sequence of moves. Note that your solution still has to finish within the time limit and terminate correctly.
Group | Score | Limits |
---|---|---|
1 | 14 | String is attached to pins and for all |
2 | 16 | The number of steps needed is at most 2 |
3 | 12 | It is guaranteed that there is a solution where one string is attached to pins 0 and 1 |
4 | 28 | |
5 | 30 | No additional constraints |