#K1586. Maximum Communication Efficiency

    ID: 24450 Type: Default 1000ms 256MiB

Maximum Communication Efficiency

Maximum Communication Efficiency

You are given a communication network between departments, which is organized as a tree. Each node in the tree represents a department, and each edge represents a direct communication link between two departments.

The communication efficiency between two departments is defined as the number of direct communications (edges) that must be traversed along the shortest path connecting them. Your task is to determine the maximum communication efficiency between any two departments in the network, which is equivalent to finding the diameter of the tree.

More formally, if \(d(u,v)\) represents the shortest distance between nodes \(u\) and \(v\), you need to compute:

\( \max_{u,v \in V} d(u,v) \)

Note: The input guarantees that the network forms a tree.

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. The first line contains an integer \(n\) (\(2 \le n \le 10^5\)) representing the number of departments.
  2. Each of the following \(n - 1\) lines contains two integers \(u\) and \(v\) which denote that there is a direct communication connection between department \(u\) and department \(v\).

outputFormat

Output a single integer via standard output (stdout) representing the maximum communication efficiency (i.e., the diameter of the tree).

## sample
5
1 2
1 3
3 4
3 5
3