CF690C2.Brain Network (medium)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 n brains and m 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 u and v (1 ≤ 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.

对僵尸思维过程的进一步研究得出了有趣的结果。如前一题所示,僵尸的神经系统由 nn 个大脑和 mm 条脑连接线组成,这些连接线将某些大脑两两相连。研究人员观察到,僵尸的智力水平主要取决于其神经系统的拓扑结构。更准确地说,我们定义两个大脑 uu 和 vv(其中 1≤u,v≤n1 \le u, v \le n)之间的距离为在这两个大脑之间传递一个思维所需经过的最少脑连接线数量。僵尸的脑延迟(brain latency) 被定义为该僵尸所有大脑两两之间距离的最大值。研究人员猜想,脑延迟是决定某只僵尸智力水平的关键参数。请编写一个程序来计算各类神经系统的脑延迟,以帮助他们验证这一猜想。

在本题中,你可以假设输入给出的任意神经系统均是合法的,即它满足简单版本中的条件 (1) 和 (2)。

输入格式

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

输入的第一行包含两个以空格分隔的整数 nn 和 mm(1 ≤ n, m ≤ 1000001 \leq n, m \leq 100000),分别表示大脑的数量(编号恰好为 11 到 nn)以及神经系统中脑连接器的数量。接下来的 mm 行描述了各个脑连接器。每个连接器由它所连接的两个大脑 aa、bb 组成(1 ≤ a, b ≤ n1 \leq a, b \leq n 且 a ≠ ba \neq 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

输入解题思路,AI测评打分。不知道怎么写?

首页