282. Cycle in a Directed Graph
MediumTopological Sort
Print YES if the directed graph contains a cycle, else NO.
Input format
Line 1: n m Next m lines: u v (edge u → v)
Output format
YES or NO
Example 1
Input
3 3 1 2 2 3 3 1
Output
YES
Example 2
Input
3 2 1 2 2 3
Output
NO
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…