Furthest vertex
Tag(s):

## Graph, Medium-Hard, Shortest path problem

Problem
Editorial
Analytics

There are n vertices.

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.

SAMPLE INPUT
3 5
1 1 2
2 1
2 3
1 1 3
2 3

SAMPLE OUTPUT
1
0
2

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

November Clash '16

OTHER PROBLEMS OF THIS CHALLENGE
• Data Structures > Advanced Data Structures
• Data Structures > Advanced Data Structures
• Algorithms > Searching