#K79962. Task Scheduling Order

    ID: 35425 Type: Default 1000ms 256MiB

Task Scheduling Order

Task Scheduling Order

You are given n tasks (numbered from 0 to n-1) and m dependency relations. Each dependency is given as a pair of integers a and b which means that task a must be completed before task b can be started.

Your task is to determine a valid order in which all the tasks can be completed such that for every dependency \(a \to b\), task \(a\) appears before task \(b\) in the ordering. If no valid ordering exists (i.e. there is a cycle in the dependencies), output an empty line.

Note: A valid order satisfies the constraint \[ \forall (a, b) \text{ in dependencies}, \quad \text{position}(a) < \text{position}(b). \]

inputFormat

The first line contains two integers n and m separated by a space, where n is the number of tasks and m is the number of dependency relations.

The following m lines each contain two integers a and b (separated by a space), representing that task a must be completed before task b.

You may assume that \(0 \leq a, b \lt n\).

outputFormat

Output a single line representing a valid ordering of the n tasks as space-separated integers. If there is no valid ordering, output an empty line.

## sample
4 3
1 0
2 1
3 2
3 2 1 0

</p>