CF690C2.Brain Network (medium)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of nn brains and mm brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of its nervous system. More precisely, we define the distance between two brains uu and vv ( 1<=u,v<=n1<=u,v<=n ) as the minimum number of brain connectors used when transmitting a thought between these two brains. The brain latency of a zombie is defined to be the maximum distance between any two of its brains. Researchers conjecture that the brain latency is the crucial parameter which determines how smart a given zombie is. Help them test this conjecture by writing a program to compute brain latencies of nervous systems.

In this problem you may assume that any nervous system given in the input is valid, i.e., it satisfies conditions (1) and (2) from the easy version.

输入格式

The first line of the input contains two space-separated integers nn and mm ( 1<=n,m<=1000001<=n,m<=100000 ) denoting the number of brains (which are conveniently numbered from 11 to nn ) and the number of brain connectors in the nervous system, respectively. In the next mm lines, descriptions of brain connectors follow. Every connector is given as a pair of brains aba b it connects ( 1<=a,b<=n1<=a,b<=n and aba≠b ).

输出格式

Print one number – the brain latency.

输入输出样例

  • 输入#1

    4 3
    1 2
    1 3
    1 4
    

    输出#1

    2
  • 输入#2

    5 4
    1 2
    2 3
    3 4
    3 5
    

    输出#2

    3
首页