#K66352. Minimum Time to Broadcast Message in a Server Network

    ID: 32401 Type: Default 1000ms 256MiB

Minimum Time to Broadcast Message in a Server Network

Minimum Time to Broadcast Message in a Server Network

You are given a network of n servers connected in the form of a tree with n - 1 bidirectional edges. The main server is labeled as 1. When a message is sent from the main server, it is transmitted simultaneously along all edges, taking 1 unit time per edge.

The task is to determine the minimum time required for the message to reach every server in the network.

This can be mathematically modeled as finding the diameter of the tree (the longest distance between any two servers) and then computing the ceiling of half of that distance: $$\lceil \frac{\text{diameter}}{2} \rceil.$$

inputFormat

The input is read from standard input (stdin). The first line contains a single integer n representing the number of servers. The next n - 1 lines each contain two space-separated integers u and v, denoting a bidirectional connection between server u and server v.

outputFormat

Output to standard output (stdout) a single integer representing the minimum time required for the message to reach all servers.## sample

6
1 2
1 3
2 4
2 5
3 6
2