#C8561. Task Completion Ordering
Task Completion Ordering
Task Completion Ordering
You are given n tasks numbered from 1 to n and m dependency relations. Each dependency is given as a pair of integers \(u\) and \(v\), which means you must complete task \(u\) before starting task \(v\).
Your task is to determine whether it is possible to complete all tasks in some order such that all the dependencies are satisfied. In other words, you need to check if the directed graph formed by these dependencies has a topological ordering.
If the total number of tasks processed in a valid topological sort is \(n\), then the answer is Yes
; otherwise, it is No
.
The condition can be mathematically stated as: if \(processed = n\), output \(Yes\); otherwise, output \(No\).
inputFormat
The first line contains two integers \(n\) and \(m\), representing the number of tasks and the number of dependencies, respectively.
Each of the next \(m\) lines contains two integers \(u\) and \(v\) (\(1 \leq u,v \leq n\)), indicating that task \(u\) must be completed before task \(v\).
outputFormat
Output a single line containing Yes
if it is possible to complete all tasks in a valid order; otherwise, output No
.
4 4
1 2
2 3
3 4
4 2
No
</p>