#K75547. Task Completion Feasibility

    ID: 34443 Type: Default 1000ms 256MiB

Task Completion Feasibility

Task Completion Feasibility

You are given \( n \) tasks and \( m \) dependencies among them. Each dependency is represented by a pair \( (u, v) \), which indicates that task \( u \) depends on task \( v \); therefore, task \( v \) must be completed before task \( u \) can be started. In other words, you need to determine whether all tasks can be completed following these restrictions. This is equivalent to checking if the directed graph formed by the tasks and dependencies is a Directed Acyclic Graph (DAG).

The input begins with two integers \( n \) and \( m \). The following \( m \) lines each contain two integers representing a dependency.

Note: Use \( \LaTeX \) format for any formulas if necessary.

inputFormat

The input is read from standard input (stdin) and follows the format below:

The first line contains two space-separated integers ( n ) (the number of tasks) and ( m ) (the number of dependencies). Each of the next ( m ) lines contains two space-separated integers ( u ) and ( v ) describing a dependency, meaning task ( u ) depends on task ( v ).

outputFormat

Output a single line to standard output (stdout) containing "YES" if it is possible to complete all tasks (i.e., there is no cycle in the dependency graph), otherwise output "NO".## sample

5 4
1 2
2 3
3 4
4 5
YES