Limits 1s, 512 MB

One day your boss explains to you that he has a bunch of computer networks that are currently unreachable from each other, and he asks you, the cable expert’s assistant, to adjoin the networks to each other using new cables. Existing cables in the network cannot be touched.

He has asked you to use as few cables as possible,but the length of the cables used does not matter to him, since the cables are optical and the connectors are the expensive parts. Your boss is rather picky on cable usage, so you know that the already existing network shave as few cables as possible.

Due to your humongous knowledge of computer networks, you are of course aware that the latency for an information packet travelling across the network is proportional to the number of hops the packet needs, where a hop is a traversal along a single cable. And since you believe a good solution to your boss’ problem may earn you that long wanted promotion, you decide to minimise the maximum number of hops needed between any pair of network nodes.

Input

On the first line, you are given two positive integers, the number cc (1c1051 ≤ c ≤ 10^5) of computers and the number ll (0lc10 ≤ l ≤ c−1) of existing cables. Then follow l lines, each line consisting of two integers a and b, the two computers the cables connect. You may assume that every computer has a unique name between 0 and n1n-1.

Output

The maximum number of hops in the resulting network.

Samples

InputOutput
6 4
0 1
0 2
3 4
3 5
3
InputOutput
11 9
0 1
0 3
0 4
1 2
5 4
6 4
7 8
7 9
7 10
4

This NCPC 2015 problem is licensed under the CC BY-SA 3.0 license.

You can find the original problem on the NCPC website.

Submit

Login to submit.

Statistics

86% Solution Ratio
ShahidulEarliest, Apr '20
mdshadeshFastest, 0.0s
mdshadeshLightest, 8.0 kB
mumith_fahim99Shortest, 3111B
Toph uses cookies. By continuing you agree to our Cookie Policy.