Sasuke's Vengeance

0

0 votes
Breadth-first search, Graph Theory, Shortest Path Algorithm
Problem

Sasuke is in search of Itachi in order to seek vengeance for killing his parents along with the whole Uchiha clan. According to the information received from Bipolar Jugo, there are N possible villages in the Land of Fire where Itachi might be present. Sasuke's unit is currently in the village 1. These villages are connected to each other by M bidirectional roads. It takes 1 whole day to travel on a road connecting two villages.

Assuming Sasuke's unit always follows the shortest route to reach a village, and can travel to exactly one village, how many days at worst can it take them to reach any of the village from village 1?

Constraints

2N2×105

N1Mmin(2×105,N(N1)/2)

1Ui,ViN

Input format

The first line contains two integers, N and M, the number of villages and the number of roads connecting them.

Next, M lines contain two space separated integers Ui,Vi, representing a bidirectional road connecting villages Ui and Vi.

Output format

Print the maximum number of days to reach any village from village 1.

Sample Input
6 7
1 2
1 4
1 5
2 3
2 4
4 6
5 6
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?