codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

690C2.md (1858B)


      1 Source: https://codeforces.com/problemset/problem/690/C2
      2 
      3 C2. Brain Network (medium)
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 Input
     26 
     27 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*).
     28 
     29 Output
     30 
     31 Print one number – the brain latency.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 4 3  
     39 1 2  
     40 1 3  
     41 1 4
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 2
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 5 4  
     54 1 2  
     55 2 3  
     56 3 4  
     57 3 5
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 3
     64 ```