## COCI '07 Contest 1 #6 Staza

View as PDF

Points: 25 (partial)
Time limit: 0.6s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

A bicycle race is being organized in a country. The transport network of the country consists of cities numbered through , with bidirectional roads connecting them. We will use the following terms:

• A path is a sequence of roads in which each road starts in the city the preceding road ended in.
• A simple path is a path which never visits a city more than once.
• A ring is a simple path ending in the same city it started in.

The network is such that there is at least one path between every pair of cities. Additionally, every road in the network is part of at most one ring.

Your task is to find the longest path for the race satisfying two constraints:

• The path may begin in any city, but must end in city 1.
• The path may visit a city more than once, but it must not contain any road more than once.

#### Input Specification

The first line of input contains two integers and – the numbers of cities and roads in the network.

Each of the following lines contains two different integers and . These numbers indicate that there is a bidirectional road between cities and . No two cities will be directly connected by more than one road.

#### Output Specification

Output the length of the longest race path on a single line.

#### Sample Input 1

4 3
1 2
1 3
2 4

#### Sample Output 1

2

#### Sample Input 2

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

#### Sample Output 2

5

#### Sample Input 3

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

#### Sample Output 3

6