Furthest vertex

5

2 votes
Graphs, Medium, Shortest Path Algorithm
Problem

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 (1n105,1q3105)

Then follow q lines. The i-th of them contains integers: typei (1typei2), ai (1an) and if typei=1 bi (1bin).

OUTPUT

Print the distance which is needed for each query of the second type.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?