#P2195. HXY造公园

    ID: 1118 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索图论并查集广度优先搜索,BFS树的直径

HXY造公园

Description

There is an existing park with n n rest spots and m m undirected edges connecting pairs of rest spots. As everyone knows, HXY is an OCD patient of "SXBK", so she plans to use magic to renovate the park and instantly keep track of the renovation. She can perform the following two operations:

  1. For a rest spot x x , query the longest path within the set of rest spots that are mutually reachable with x x .
  2. For two rest spots x,y x, y , if x x and y y are already mutually reachable, ignore this operation. Otherwise, choose one rest spot from all rest spots reachable from x x and one rest spot from all rest spots reachable from y y (including x x and y y themselves), then add one edge between these two chosen rest spots. This choice should minimize, in the park after the connection, the length of the longest path within the region containing x x and y y (that is, the set consisting of all rest spots and edges reachable from x x and y y ).

HXY plans to perform q q operations. Please answer her queries about the park (operation 1) or carry out her operation (operation 2).

Note: All edges have length 1 1 . It is guaranteed that there are no cycles. The longest path is defined as follows: for vertices v1,v2,,vk v_1, v_2, \cdots, v_k , if for every vi v_i and vi+1 (1ik1) v_{i+1} \ (1 \le i \le k-1) there is an edge connecting them, then the longest path in the region containing any vj (1jk) v_j \ (1 \le j \le k) has length k1 k - 1 .

Input Format

  • The first line contains three positive integers n,m,q n, m, q .
  • The next m m lines each contain two positive integers xi,yi x_i, y_i , indicating that there is an undirected edge between xi x_i and yi y_i .
  • The next q q lines each describe an operation.
    • If the first number is 1 1 , this is operation 1; then there is one positive integer xi x_i , the rest spot to query.
    • If the first number is 2 2 , this is operation 2; then there are two positive integers xi,yi x_i, y_i , the two rest spots for the operation.

Output Format

The number of output lines equals the number of operation 1.

On each line, output the answer to the corresponding operation 1 query.

6 0 6
2 1 2
2 3 4
2 5 6
2 3 2
2 5 3
1 1
4

Hint

Constraints and Conventions

  • For 10% 10\% of the testdata, only operation 1 exists.
  • For 30% 30\% of the testdata, 0m<n20 0 \le m < n \le 20 , 1q5 1 \le q \le 5 .
  • For 60% 60\% of the testdata, 0m<n2000 0 \le m < n \le 2000 , 1q1000 1 \le q \le 1000 .
  • For 100% 100\% of the testdata, 0m<n3×105 0 \le m < n \le 3 \times 10^5 , 1q3×105 1 \le q \le 3 \times 10^5 .

Translated by ChatGPT 5