There are tasks, which have to be done one by one. Some tasks must be done before others: there are precedence relations between tasks. Write a program that prints all possible ways to order the tasks according to the given precedences.
Input consists of a natural number , followed by a natural number , followed by different pairs , indicating that task must be done before task . Suppose that the tasks are numbered from 0 to .
Print, one per line and in lexicographic order, all the ways of sorting the tasks according to the given precedences. There will always be at least one solution.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T11:12:09.662Z
© Jutge.org, 2006–2026.
https://jutge.org