IntermediateRating 1300
Is There a Loop?
A directed graph has n nodes and m one-way edges. Print YES if you can start at some node and follow edges back to it, otherwise NO.
Input
n and m; then m lines 'u v' (edge u → v).
Output
YES or NO.
Sample 1
Input
3 3 1 2 2 3 3 1
Output
YES
Sample 2
Input
3 2 1 2 2 3
Output
NO
Output appears here