HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Cycle detection

Guest
• Discussion of problem (1)

Section problems

• Gifts of Santa Claus
• Rectangles on a plane
• Permutations
• Reverse permutation
• Nameplates
• Adjacency matrix to edges list
• Edges list to Adjacency matrix
• Cities and roads
• Cycle detection
• Diameter of graph
• Divisors count
• GCD of ones
• Prime numbers
• Set cover problem
• Shopping
• Corridor
• D. Love-Hate

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 12000/2000/2000/2000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

Given directed unweighted graph. Find any cycle in it and print it if there is one.

Input

The first line of the input contains two integers N and M (1 ≤ N ≤ 100000, 1 ≤ M ≤ 100000) where N denotes the number of verticies, M - number of edges. Each of the following M lines contains two integers - numbers of vertices connected with edges.

Output

Print "NO" if there isn't any cycle. Otherwise print "YES" on the first line and numbers of vertices in the cycle on the second line, in order they appear in cycle.

Example

stdin stdout

2 2
1 2
2 1

YES
2 1

3 2
1 2
1 3
NO
Для отправки решений необходимо выполнить вход.

www.contester.ru