Problems
Find a cycle
Find a cycle
The directed and unweighted graph is given. Determine, does it contain a cycle. If yes, then print any of them.
\InputFile
The first line contains two positive integers $n$ and $m~(1 \le n \le 10^5, 1 \le m \le 10^5)$ --- the number of vertices and edges in graph respectively. In the next $m$ lines the edges are given. Each edge is described with a pair of numbers --- the numbers of initial and final vertex respectively.
\OutputFile
If the graph does not contain the cycle, print "\textbf{NO}", otherwise print "\textbf{YES}" and then the list of vertices in the order of cycle traversal.
\includegraphics{https://static.e-olymp.com/content/61/61160e4e1774497c1f462ae3f37766fb5cd2c2f1.gif}
Input example #1
2 2 1 2 2 1
Output example #1
YES 1 2
Input example #2
6 7 1 2 1 5 2 3 2 4 4 6 6 5 5 2
Output example #2
YES 2 4 6 5