문제
Little Fran received a wooden frame in the shape of a regular polygon as a gift. As polygon has
Remove a stick.
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
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
Since he is busy doing operations and having fun, he asks for your help!
“Fan” triangulation in vertex
Let the number of needed operations be
As the number of such sequences can be huge, little Fran is only interested in its remainder modulo
입력
In the first line are integers
In each of the next
In each of the next
If
If
출력
For every event of type
부분문제
번호 | 점수 | 조건 |
---|---|---|
#1 | 11점 | |
#2 | 15점 | |
#3 | 27점 | |
#4 | 11점 | |
#5 | 36점 | No additional constraints. |
예제1
43
1 3
2 1
1 1 3 2 4
2 1
01
1 1
Starting triangulation is already a “fan” triangulation in vertex
예제2
54
1 3
3 5
2 1
2 2
1 1 3 2 5
2 2
11
2 1
1 1
Only sequence of operations for the first query:
Only sequence of operations for the second query:
Only sequence of operations for the third query:
예제3
93
1 5
1 7
2 4
2 5
5 7
7 9
2 1
1 2 5 1 4
2 1
412
3 6