We must perform tasks, one at a time. Furthermore, some tasks must be done before others: there are precedence relations between tasks. Write a program to print a way to sort the tasks satisfying the given precedences.
Input consists of several cases. Every case begins with , followed by , followed by distinct pairs that indicate that task must be done before task . You can assume , , and that the tasks are numbered from 0 to .
For every case, print the lexicographically smallest order of the tasks that fulfills the given precedences. There will always be, at least, one solution.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T10:10:32.072Z
© Jutge.org, 2006–2026.
https://jutge.org