#P6335. Longest Route Ending at City 1
Longest Route Ending at City 1
Longest Route Ending at City 1
A bicycle race is held in a country whose transportation network consists of n cities (numbered 1 to n) connected by m bidirectional roads. We define the following terms:
- Route: A sequence of roads where each road starts at the ending city of the previous road.
- Simple Route: A route that does not visit any city more than once.
- Cycle: A simple route whose starting and ending cities are the same.
It is guaranteed that for any two cities there is at least one route connecting them, and each road in the network is contained in at most one cycle.
Your task is to find the longest route (in terms of the number of roads traversed) that satisfies the following constraints:
- The route may start at any city but must end at city 1.
- The route may visit the same city multiple times, but no road can be used more than once.
Output the length of the longest valid route.
inputFormat
The first line contains two integers n and m — the number of cities and the number of roads, respectively. Each of the following m lines contains two integers u and v indicating that there is a bidirectional road connecting city u and city v. It is guaranteed that the graph is connected and that each road is part of at most one cycle.
outputFormat
Print a single integer — the length (number of roads) of the longest route ending at city 1.
sample
3 3
1 2
2 3
3 1
3