#K70012. Task Order Scheduling
Task Order Scheduling
Task Order Scheduling
You are given n tasks and d dependency pairs. Each dependency is given as a pair of integers a and b which denotes that task a must be completed before task b can begin. In formal notation, the dependency can be represented as \(a \rightarrow b\). Your task is to determine a valid order to execute all tasks such that all the dependency relations are satisfied.
If there exists multiple valid orders, you may output any one of them. However, if it is impossible to complete all tasks because of a cyclic dependency, output "NOT POSSIBLE".
Note: The ordering (if exists) is unique according to the algorithm provided in the sample solutions.
inputFormat
The first line contains two integers n
and d
, where n
is the number of tasks and d
is the number of dependencies.
The next d
lines each contain two integers a
and b
, representing a dependency that task a
must be completed before task b
.
\(1 \leq a,b \leq n\)
outputFormat
Output a single line. If a valid ordering exists, output the tasks in a valid order separated by a single space. If no valid ordering exists, output "NOT POSSIBLE".
## sample3 2
1 2
2 3
1 2 3
</p>