题号:NC231372
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
There is an undirected graph with

vertices and no edges initially.
Let's define the weight of the path consisting of

edges with indices

as
%20%5Cbmod%20F)
.
Notice that a path may not be simple. That is, it can go through the same vertices or the same edges multiple times, and the weight will also be the sum for multiple times if so.
You need to perform

operations.
There are

types of operations:

: add an edge between

and

with weight

.

: delete the edge added in the

-th operation.

: If there is a path between

and

with weight

, print

. Otherwise, print

. Notice that a path may not be simple.
输入描述:
The first line contains
integers
--- the numbers of vertices of the graph, the number of operations in the graph, and the modulo.
Then
lines follow. The
-th line contains the
-th operation. The format of the operation input is shown above.
In operations, all tokens are non-negative integers.
.
It's guaranteed that in each operation

, the

must be an operation of type

and it has not been deleted by another operation

.
第一行有

个整数,
)
。
接下来有

行,每行描述一个操作。
操作格式同题目描述。
题目保证,所有输入的数均为非负整数,且

.
题目保证执行第

种操作时,

对应的操作为第

种,且还未被删。
输出描述:
For each operation of types

, output a line containing the answer.
对于每个询问操作,输出一行一个整数表示答案。
示例1
输入
复制
10 19 96
1 3 1 48
1 3 2 16
2 2
2 1
1 3 3 24
1 2 2 16
1 2 3 6
1 2 3 48
1 2 2 48
1 1 3 16
1 3 3 48
2 5
3 3 4 16
3 3 3 8
1 2 1 48
2 6
3 3 1 32
2 7
2 8