#P2195. HXY造公园
HXY造公园
Description
There is an existing park with rest spots and 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:
- For a rest spot , query the longest path within the set of rest spots that are mutually reachable with .
- For two rest spots , if and are already mutually reachable, ignore this operation. Otherwise, choose one rest spot from all rest spots reachable from and one rest spot from all rest spots reachable from (including and 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 and (that is, the set consisting of all rest spots and edges reachable from and ).
HXY plans to perform operations. Please answer her queries about the park (operation 1) or carry out her operation (operation 2).
Note: All edges have length . It is guaranteed that there are no cycles. The longest path is defined as follows: for vertices , if for every and there is an edge connecting them, then the longest path in the region containing any has length .
Input Format
- The first line contains three positive integers .
- The next lines each contain two positive integers , indicating that there is an undirected edge between and .
- The next lines each describe an operation.
- If the first number is , this is operation 1; then there is one positive integer , the rest spot to query.
- If the first number is , this is operation 2; then there are two positive integers , 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 of the testdata, only operation 1 exists.
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号