Problem list
Log in
#coci00668 · COCI 2023/2024 Contest 4

Lepeze

Diamond II 2.0 s 512 MB

Little Fran received a wooden frame in the shape of a regular polygon as a gift. As polygon has $n$ vertices, he also received ^{n($n - 3$)} 2 wooden sticks that match each possible diagonal. Vertices of the polygon are labelled with integers from 1 to $n$ in counterclockwise order. In the beginning, Fran arranged $n - 3$ sticks inside the frame in such a way that every stick touches two non-neighboring vertive of the frame, and no two sticks cross each other. In other words, he made a triangulation. As that was not interesting enough for him, he decided to play with this configuration by applying a particular operation that consists of two steps:

  1. Remove a stick.
  2. Add a new stick in such a way that we obtain a new triangulation. We characterize the operation with an ordered pair of unordered pairs ((a, b), (c, d)) which signifies that little Fran removed a stick touching vertices $a$ and $b$, and added a stick touching vertices $c$ and $d$. Fran loves hand fans so, while doing these operations, he sometimes asks himself: “How many operations $is$ needed $to$ transform this triangulation into $a$ “fan” triangulation $in$ vertex $x$, and, $in$ how many ways $is$ this achievable?”. Since he is busy doing operations and having fun, he asks for your help! “Fan” triangulation in vertex $x$ is a triangulation where all diagonals have a common endpoint, namely vertex $x$. Let the number of needed operations be $m$. Let $f_{1}$, $f_{2}$, . . . , $f_{m}$ be a sequence of operations that, when applied in given order, achieves wanted triangulation, thus representing one way of getting there. Let $s_{1}$, $s_{2}$, . . . , $s_{m}$ be another such sequence. Two sequences are distinct if there exists an index $i$ such that $f_{i}$̸ = $s_{i}$. As the number of such sequences can be huge, little Fran is only interested in its remainder modulo $10^{9} + 7$.

Input

In the first line are integeres $n$ and $q$ ($4 \le n \le 2 \cdot 10^{5}$, $1 \le q \le 2 \cdot 10^{5}$), the number of vertices and the number of events In each of the next $n - 3$ lines there are integers $x_{i}$, $y_{i}$ ($1 \le x_{i}$, $y_{i} \le n$), the labels of vertices that the $i$-th stick touches. In each of the next $q$ lines there is the integer $t_{i}$ ($1 \le t_{i} \le 2$) that represents the type of event. If $t_{i} = 1$, it is followed by 4 integers $a_{i}$, $b_{i}$, $c_{i}$, $d_{i}$ ($1 \le a_{i}$, $b_{i}$, $c_{i}$, $d_{i} \le n$) that signify an operation (($a_{i}$, $b_{i}$), ($c_{i}$, $d_{i}$) is being made at that moment. It is guaranteed that given operation can be realized. If $t_{i} = 2$, it is followed by an integer $x_{i}$ ($1 \le x_{i} \le n$), which means that little Fran is interested in data for the “fan” triangulation at vertex $x_{i}$ in relation to the current triangulation.

Output

For every event of type 2, in order they came in input, output two integers, minimal number of operations needed and number of ways to get to the target triangulation using minimal number of operations.

Example 1

Input
4 3
1 3
2 1
1 1 3 2 4
2 1
Output
0 1
1 1

Example 2

Input
5 4
1 3
3 5
2 1
2 2
1 1 3 2 5
2 2
Output
1 1
2 1
1 1

Example 3

Input
9 3
1 5
1 7
2 4
2 5
5 7
7 9
2 1
1 2 5 1 4
2 1
Output
4 12
3 6

Clarification of the first example: Starting triangulation is already a “fan” triangulation in vertex 1, so little Fran must do no operations, which there is one way of doing so. After executing a given operation, there is now only one way to get it to the previous state and that is by applying operation ((2, 4), (1, 3)). Clarification of the second example: Only sequence of operations for the first query: ((3, 5), (1, 4)). Only sequence of operations for the second query: ((1, 3), (2, 5)), ((3, 5), (2, 4)). Only sequence of operations for the third query: ((3, 5), (2, 5)).

Source
COCI 2023/2024 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code