#B4016. Tree Diameter

    ID: 11673 Type: Default 1000ms 256MiB

Tree Diameter

Tree Diameter

Given an unweighted tree with \(n\) nodes, your task is to compute the tree's diameter. The diameter of a tree is defined as the length of the longest simple path between any two nodes in the tree, measured by the number of edges.

inputFormat

The first line contains a single integer \(n\) (where \(1 \leq n \leq 10^5\)), representing the number of nodes in the tree. Each of the next \(n - 1\) lines contains two integers \(u\) and \(v\) (with \(1 \leq u, v \leq n\)), denoting an edge between node \(u\) and node \(v\).

outputFormat

Output a single integer: the diameter of the tree.

sample

1
0