Tom wants to learn how to cast some spells. However, as some spells are more advanced than others, there are some spells you have to learn before you learn others. There are some very interesting spells that he wishes to learn. However, many of them are very advanced, which means that he will have to learn many other spells before he learns the interesting spell.
Input
Output
The spells you will have to learn before Tom can learn the spell
Constraints
Subtask 1 [30%]
Subtask 2 [70%]
Sample Input
5 3 2
0 1
1 2
3 4
Sample Output
0 1
Explanation
To learn spell 2, he will have to learn spell 1. To learn spell 1, he will have to learn spell 0.
Comments
Time limit seems too strict. Can't even read in input without TLEing (even with C++ and fast input).
Use https://ideone.com/X1tP8Q.
Does the output have to be sorted?
The output should be in the order that you must learn the spells