#P5489. EntropyIncreaser 与 动态图

EntropyIncreaser 与 动态图

Background

It is said that when NaCly_Fish was having a meal with EntropyIncreaser\mathsf E \color{red}\mathsf{ntropyIncreaser}, he asked her a question: “Given an undirected graph that supports dynamic edge insertions, how do we find the number of articulation points between two vertices?”

EntropyIncreaser\mathsf E \color{red} \mathsf{ntropyIncreaser} thought for a few seconds and said: “Isn’t this a super easy problem? You can do it however you want.” Then she explained an algorithm in just a few sentences.

But NaCly_Fish still did not understand it. Please teach her how to solve this problem.

Problem Description

There is a graph with nn vertices, initially with no edges.
There are qq operations, of 33 types, as follows:

  • 1 u v means adding an undirected edge between uu and vv.
  • 2 u v means querying the number of bridges between uu and vv.
  • 3 u v means querying the number of articulation points between uu and vv.

In particular, for operations 22 and 33, if uu and vv are not connected, output 1-1.


To avoid ambiguity, here are the definitions of the number of bridges and articulation points between two vertices:

Let SS be the intersection of the vertex sets of all paths that contain both uu and vv. Define the number of elements in SS as the number of articulation points between uu and vv.
Let TT be the intersection of the edge sets of all paths that contain both uu and vv. Define the number of elements in TT as the number of bridges between uu and vv.


This problem is strictly online.
Starting from the second line, in each input, u,vu,v must be XORed with last\text{last} to get the actual u,vu,v.
last\text{last} is the answer of the most recent query whose answer is not 1-1, and initially last=0\text{last}=0.
ps: If you do not know what XOR means, see here: xor.

Input Format

The first line contains two positive integers n,qn,q, representing the number of vertices and the number of operations.
The next qq lines each contain three integers, describing one operation.

Output Format

For each operation of type 22 or 33, output one line with one integer representing the answer.

5 10
1 1 2
1 2 3
2 1 3
3 0 1
1 3 1
1 1 6
2 3 7
1 6 7
1 7 1
3 3 6
2
2
-1
3

Hint

The background story is a real event.

Sample Explanation

The actual operations are:

5 10
1 1 2
1 2 3
2 1 3
3 2 3
1 1 3
1 3 4
2 1 5
1 4 5
1 5 3
3 1 4

Constraints

For 20%20\% of the testdata, 1n,q20001\le n,q \le 2000.
For another 30%30\% of the testdata, all operations of type 22 and 33 occur after a type 11 operation.
For 100%100\% of the testdata, 1n1051\le n \le 10^5, 1q3×1051\le q \le 3\times 10^5.

For type 11 operations, it is guaranteed that uvu\neq v.

By: NaCly_Fish


Welcome to join the EI Captain fan group. Group number: 747262201747262201.

Translated by ChatGPT 5