#P4244. Cactus Graph Diameter

    ID: 17491 Type: Default 1000ms 256MiB

Cactus Graph Diameter

Cactus Graph Diameter

A cactus graph is an undirected connected graph in which every edge belongs either to no simple cycle (i.e. it is a bridge) or to exactly one simple cycle. A simple cycle is a cycle that does not pass through any vertex more than once.

Given a cactus graph where every edge has a weight of 1, your task is to compute the diameter of the graph. The diameter of a graph is defined as the maximum distance between any two vertices, where the distance between two vertices is the length (i.e. number of edges) of a shortest path connecting them.

Mathematically, if we denote the distance between vertices u and v as \( d(u,v) \), then the diameter is given by:

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

inputFormat

The first line contains two integers \( n \) and \( m \) which denote the number of vertices and the number of edges in the graph, respectively.

Each of the following \( m \) lines contains two integers \( u \) and \( v \) indicating that there is an undirected edge between vertices \( u \) and \( v \). The input graph is guaranteed to be a cactus graph.

outputFormat

Output a single integer representing the diameter of the graph.

sample

6 5
1 2
2 3
3 4
4 5
5 6
5