#C6094. Tree Diameter

    ID: 49816 Type: Default 1000ms 256MiB

Tree Diameter

Tree Diameter

Given an undirected tree (T = (V, E)) with (n) vertices, your task is to compute its diameter. The diameter is defined as the longest distance (in terms of the number of edges) between any two vertices in the tree. Note that the tree is connected and acyclic, i.e. it has no cycles. All vertices are 1-indexed.

For example, consider a chain of 5 vertices: 1-2, 2-3, 3-4, 4-5. The diameter here is 4 because the longest path spans 4 edges.

inputFormat

Input is provided via standard input. The first line contains a single integer (n) ((1 \le n \le 100)), representing the number of vertices. Each of the following (n-1) lines contains two space-separated integers (u) and (v), describing an edge between vertices (u) and (v).

outputFormat

Output a single integer via standard output, which is the diameter of the tree.## sample

1
0