ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Неотсортированные > задача:


Cycle detection

Гость
• Обсуждение задачи (1)

Задачи раздела

• Going to the Movies
• A to the power of B
• X to the power of Y
• Connected components
• Arithmetic Operators
• REVERSE ORDER OF WORDS
• A Palace with Many Columns
• Nameplates
• Cycle detection
• Cities and roads
• Adjacency matrix to edges list
• Edges list to Adjacency matrix
• Permutations
• Reverse permutation
• Divisors count
• GCD of ones
• Set cover problem

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 12000/2000/2000/2000 мс. Лимит памяти 65000/65000/65000/65000 Кб.

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