#C10836. Tree Diameter

    ID: 40085 Type: Default 1000ms 256MiB

Tree Diameter

Tree Diameter

Given a tree with n nodes and n-1 edges, your task is to compute the diameter of the tree. The diameter of a tree is defined as the maximum distance between any two nodes in the tree. The distance between two nodes is the number of edges in the unique path connecting them.

Mathematically, if the two most distant nodes are u and v, then the tree diameter d can be computed as:

d=maxu,vVdist(u,v)d = \max_{u,v \in V} dist(u,v)

Input is given via standard input, and the answer must be printed to standard output.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains an integer n (1 ≤ n ≤ 105), the number of nodes in the tree.
  2. If n is greater than 1, the next n - 1 lines each contain two integers u and v specifying an edge between nodes u and v (1-indexed).

outputFormat

Output a single integer, the diameter of the tree.

## sample
1
0

</p>