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

Сборники > Camp. Turkey > задача:


Cycle detection

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

Задачи сборника

• 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
• Делители

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

Если у вас есть предложения или пожелания по работе 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