#P10230. [COCI 2023/2024 #4] Lepeze
[COCI 2023/2024 #4] Lepeze
Background
Translated from COCI 2023/2024 Contest #4 T3 “Lepeze”.
Problem Description
Little Fran received a gift — a regular polygon wooden frame. Since the polygon has vertices, he also received wooden sticks, one for each diagonal. The vertices of the polygon are labeled from to in counterclockwise order. At the beginning, Fran places sticks inside the frame so that each stick touches two non-adjacent vertices of the frame, and no two sticks intersect. In other words, he makes a triangulation. Since this is not interesting enough for him, he decided to perform a specific operation to change the placement, consisting of two steps:
- Remove one stick.
- Add a new stick so that we obtain a new triangulation.
We describe this operation by an ordered pair of unordered pairs , meaning that Fran removed the stick touching vertices and , and added the stick touching vertices and .
Fran likes fans, so while performing these operations, he sometimes asks himself: “How many operations are needed to transform this triangulation into a ‘fan’ triangulation centered at vertex , and in how many ways can it be done?”
Since he is busy operating and having fun, he asks for your help.
A “fan” triangulation centered at vertex is a triangulation in which all diagonals share a common endpoint, namely vertex .
Let the required number of operations be . Let be a sequence of operations such that performing them in this order results in a triangulation that satisfies the requirement. Let be another such sequence. If there exists an index such that , then the two sequences are different.
Since the number of such sequences can be very large, Fran only cares about its value modulo .
Input Format
The first line contains two integers and , denoting the number of vertices and the number of events.
The next lines each contain two integers , describing the two vertices touched by the -th stick.
The next lines each describe one event. The first integer is , denoting the event type.
If , then four more integers follow, describing one operation . It is guaranteed that the given operation is feasible.
If , then one integer follows, meaning that Fran is interested in the data for the “fan” triangulation centered at vertex in the current state.
Output Format
For each event of type , in the order they appear in the input, output two integers: the minimum number of operations required, and the number of ways to reach the target triangulation using the minimum number of operations.
4 3
1 3
2 1
1 1 3 2 4
2 1
0 1
1 1
5 4
1 3
3 5
2 1
2 2
1 1 3 2 5
2 2
1 1
2 1
1 1
9 3
1 5
1 7
2 4
2 5
5 7
7 9
2 1
1 2 5 1 4
2 1
4 12
3 6
Hint
Sample Explanation 1
The initial triangulation is already a “fan” triangulation centered at vertex , so Fran does not need to perform any operations, and there is one way to do it. After performing the given operation, there is only one way to restore it to the previous state, namely performing the operation .
Sample Explanation 2
The first query corresponds to the unique operation sequence: .
The second query corresponds to the unique operation sequence: .
The third query corresponds to the unique operation sequence: .
Subtasks
| Subtask ID | Additional Constraints | Points |
|---|---|---|
| For all , , and there are no events with | ||
| No additional constraints |
Translated by ChatGPT 5