There are n vertices.
Your task is to perform q queries:
1 a b - add an undirected edge of the length 1 between vertices a and b
2 a - find the distance to the furthest vertex reachable from the vertex a
Guaranteed that graph will not contain loops and cycles during all the time.
\(INPUT\)
First line of the input contains two integers n and q \((1 \leq n \leq 10^5, 1 \leq q \leq 3 \cdot 10^5)\)
Then follow q lines. The i-th of them contains integers: \(type_i\) \((1 \leq type_i \leq 2)\), \(a_i\) \((1 \leq a \leq n)\) and if \(type_i = 1\) \(b_i\) \((1 \leq b_i \leq n)\).
\(OUTPUT\)
Print the distance which is needed for each query of the second type.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor