A workflow of n steps has ordering constraints given as directed edges (u v means u before v). Decide whether there is exactly one valid ordering of all steps. There is exactly one ordering if and only if the graph is acyclic and, at every stage of a topological scan, exactly one step has all its prerequisites already done (never a genuine choice). If the graph is cyclic (no valid ordering) or if more than one ordering exists, the answer is negative.
Input format
Line 1: two integers n and m — the number of nodes (labeled 0 through n-1) and the number of directed edges.
Each of the next m lines: two integers u v, a directed edge from to (read as: must come before ).
Output format
Print YES if there is exactly one valid ordering, otherwise NO.
Constraints
- 1 <= n <= 2000
- 0 <= m <= 5000
- 0 <= u, v <= n-1