#P5247. 【模板】动态图连通性
【模板】动态图连通性
Description
This is a template problem.
You need to maintain an undirected simple graph (that is, an undirected graph with no self-loops and no multiple edges). You are required to add an edge, delete an edge, and query whether two vertices are connected.
: Add an edge. It is guaranteed that it does not exist.
: Delete an edge. It is guaranteed that it exists.
: Query whether two vertices are connected.
To keep the solution online, this problem uses a special input method.
Assume you maintain a variable , with initial value .
For each input vertex , the actual vertex index used in the query or modification is , where is the bitwise XOR operation.
After decoding each query , if they are connected, then will be updated to ; otherwise it will be updated to .
Input Format
The first line contains two integers .
The next lines each contain three integers . denotes the operation number.
Output Format
For each query with , output one line Y or N, indicating whether the two vertices are connected.
200 5
2 123 127
0 4 0
2 4 0
1 4 0
2 0 4
N
Y
N
4 10
0 1 2
0 2 3
0 3 1
2 1 4
0 0 7
2 5 0
1 3 2
2 0 5
1 0 2
2 0 5
N
Y
Y
N
Hint
Due to the addition of hack testdata, the data distribution is not as described below. The following is for reference only.
For test point , .
For test point , .
For test point , , and the number of queries is .
For test point , .
For test point , , there is no operation , and about are operation .
For test point , , there is no operation , and about are operation .
For test point and , .
For test point , , the graph is a tree, and its diameter is .
For test point , , the graph is a tree, and the degree of each vertex is .
There is also some additional testdata with guarantees .
Translated by ChatGPT 5
京公网安备 11011102002149号