eolymp
bolt
Try our new interface for solving problems
Problems

Ordering tasks

Ordering tasks

John has $n$ tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. \InputFile Consist of several instances of the problem. Each instance begins with a line containing two integers: number of tasks $n~(1 \le n \le 100)$, numbered from $1$ to $n$ and number $m$ of direct precedence relations between tasks. After this, there will be $m$ lines with two integers $i$ and $j$, representing the fact that task $i$ must be executed before task $j$. An instance with $n = m = 0$ will finish the input. \OutputFile For each instance, print a line with $n$ integers representing the tasks in a possible order of execution. \includegraphics{https://static.e-olymp.com/content/c2/c2a3411de349a23ae77712d20eb0be9079678e9a.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
6 6
1 2
3 2
4 2
2 5
6 5
4 6
3 1
3 2
0 0
Output example #1
3 1 4 2 6 5
1 3 2