#P2542. [AHOI2005] 航线规划
[AHOI2005] 航线规划
Description
Exploration of planet Samuel has achieved great success, so scientists turned their attention to the galaxy where planet Samuel resides—a vast Samuel Galaxy composed of hundreds of millions of planets.
After long-term probing, the Samuel II supercomputer of the interstellar space station has located the spatial coordinates of planets in the Samuel Galaxy and numbered these planets from to .
Some advance spacecraft have set out and opened exploration routes between planets.
Exploration routes are bidirectional. For example, if an exploration route is opened from planet to planet , then the route can also be used from planet to planet .
For example, see the figure below:

Among planets, there are exploration routes.
For two planets and , if removing a certain route makes it impossible to travel from planet to planet , we call that route a critical route.
Obviously, in the figure above, there is critical route between planets and : that is, the route.
However, due to unknown magnetic storms and planetary collisions in the universe, some existing routes are damaged. As more and more routes are destroyed and exploration ships cannot repair them in time, the number of critical routes between two planets will increase.
Suppose in the figure above, the route (from planet to planet ) is destroyed. At this time, there are critical routes between planets and : , , and .
Xiao Lian’s task is to continuously monitor route destructions and report, at any time, the number of critical routes between two planets. Please help complete this task.
Input Format
The first line contains two integers, representing the number of planets and the initial number of routes .
The next lines each contain two distinct integers , indicating that there is a route between planet and planet .
Then follow several lines. Each line first gives an integer , indicating the type of an operation.
- If , then two integers follow, asking how many critical routes currently exist between planets and .
- If , then two integers follow, indicating that the route between and is destroyed.
- If , the input ends and no further operations follow.
Output Format
For each query with , output one integer on a separate line indicating the number of critical routes.
5 5
1 2
1 3
3 4
4 5
4 2
1 1 5
0 4 2
1 5 1
-1
1
3
Hint
Constraints and Conventions
- , .
- , .
- Regardless of how routes are destroyed, at any time any two planets can reach each other. In the entire testdata, between any two planets there is at most one direct route.
- For operations with , it is guaranteed that the route exists before the operation.
- The total number of queries and route destructions does not exceed .
Update: 2025.6.27 Added one set of testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号