#P10942. Tightened Ropes
Tightened Ropes
Tightened Ropes
GF and his cat received a special toy consisting of \(n\) metal rings (labeled from \(1\) to \(n\)) and \(m\) ropes. Each rope connects two distinct rings and all ropes have the same length. GF holds ring \(L\) in his left hand and the cat holds ring \(R\) (with \(L\neq R\)) in its right (or paw) and they pull in opposite directions. When they pull, the ropes that lie along the chosen connection between \(L\) and \(R\) become tightened. In a situation where there are several ways to connect the two rings with the same number of ropes, only one of these paths is considered tightened. In other words, even if a cycle (for example, \(1\to2\to4\to3\to5\to6\to1\)) provides two equivalent paths between two rings (say, \(1\) and \(3\)), only one set of ropes is counted.
Your task is to choose two rings \(L\) and \(R\) such that the number of tightened ropes (which is exactly the number of ropes along a shortest path between them) is maximized. Essentially, you need to compute the maximum shortest path length (also known as the diameter) among all pairs of rings in the toy. Note that if the toy consists of several disconnected parts, you should compute the diameter for each connected component and output the overall maximum.
Input Constraints: \(2 \leq n, m \leq \text{some reasonable limit}\). The ropes are undirected edges connecting two different rings.
inputFormat
The first line contains two integers \(n\) and \(m\) --- the number of metal rings and the number of ropes, respectively.
Each of the following \(m\) lines contains two integers \(u\) and \(v\) indicating that there is a rope connecting ring \(u\) and ring \(v\).
outputFormat
Output a single integer, the maximum number of tightened ropes, i.e. the length of the longest shortest path (diameter) among the connected components of the toy.
sample
6 6
1 2
2 3
3 4
4 5
5 6
6 1
3