Лимит времени 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 |
Для отправки решений необходимо выполнить вход.
|