#K93237. Minimum Activation Time

    ID: 38375 Type: Default 1000ms 256MiB

Minimum Activation Time

Minimum Activation Time

You are given a tree consisting of N nodes (labeled from 0 to N-1) and N-1 bidirectional edges. In this tree, each edge represents a SkyBridge connection between SkyPylons. The activation process starts at a single node and in one time unit, all neighboring nodes of any activated node become activated. Your task is to determine the minimum time required to activate all the SkyPylons if the initial activation point is optimally chosen.

It can be shown that the answer is the radius of the tree. If the diameter of the tree is denoted by \(d\), then the minimum activation time is given by:

[ T = \left\lceil \frac{d}{2} \right\rceil ]

Here, \(\lceil x \rceil\) represents the ceiling function of \(x\). For example, if the diameter is 3 (which occurs in a chain of 4 nodes), the answer would be \(\lceil 3/2 \rceil = 2\).

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  • The first line contains a single integer N, the number of SkyPylons.
  • The following N-1 lines each contain two integers u and v representing an edge between nodes u and v.

It is guaranteed that the given edges form a tree.

outputFormat

Output a single integer to standard output (stdout) representing the minimum time required to activate all SkyPylons.

## sample
7
0 1
0 2
1 3
1 4
2 5
2 6
2