#P2542. [AHOI2005] 航线规划

    ID: 1557 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2005线段树各省省选安徽O2优化最近公共祖先,LCA树链剖分,树剖

[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 nn planets in the Samuel Galaxy and numbered these planets from 11 to nn.

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 11 to planet 33, then the route can also be used from planet 33 to planet 11.

For example, see the figure below:

Among 55 planets, there are 55 exploration routes.

For two planets AA and BB, if removing a certain route makes it impossible to travel from planet AA to planet BB, we call that route a critical route.

Obviously, in the figure above, there is 11 critical route between planets 11 and 55: that is, the 454 \leftrightarrow 5 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 424 \leftrightarrow 2 (from planet 44 to planet 22) is destroyed. At this time, there are 33 critical routes between planets 11 and 55: 131 \leftrightarrow 3, 343 \leftrightarrow 4, and 454 \leftrightarrow 5.

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 nn and the initial number of routes mm.

The next mm lines each contain two distinct integers u,vu, v, indicating that there is a route between planet uu and planet vv.

Then follow several lines. Each line first gives an integer opop, indicating the type of an operation.

  • If op=1op = 1, then two integers u,vu, v follow, asking how many critical routes currently exist between planets uu and vv.
  • If op=0op = 0, then two integers u,vu, v follow, indicating that the route between uu and vv is destroyed.
  • If op=1op = -1, the input ends and no further operations follow.

Output Format

For each query with op=1op = 1, 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

  • 1n3×1041 \leq n \leq 3 \times 10^4, 1m1051 \leq m \leq 10^5.
  • 1op1-1 \leq op \leq 1, 1u,vn1 \leq u, v \leq n.
  • 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 op=0op = 0, it is guaranteed that the route uvu \leftrightarrow v exists before the operation.
  • The total number of queries and route destructions does not exceed 4×1044 \times 10^4.

Update: 2025.6.27 Added one set of testdata.

Translated by ChatGPT 5