There is always a list of things to be done!
Here is a list left for you this morning by your parental figure:
(It is nice that your parental figure makes sure you watch television, and not just use the internet all day long.)
Your parental figure has also set constraints on the order of these tasks:
Your to-do list above can now be abbreviated as:
1,7
1,4
2,1
3,4
3,5
where x,y means that task number x must be done before task number y.
During the day, your parental figure emails you additional instructions. Write a program that uses your original to-do list together with the additional instructions to output your jobs in an order in which they can be completed. If they cannot all be completed, output that there is no way to complete these tasks and that you are just going to go to bed.
You are given pairs of numbers, one number per line, representing the additional instructions to combine with the original to-do list above. In each pair, the first number x and the second number y mean that task x must be done before task y. The input ends with the pair 0 and 0. There will be at most 10 additional constraints.
Output the tasks on a single line, separated by single spaces, in the order they should be performed. If the tasks cannot all be completed, output exactly:
Cannot complete these tasks. Going to bed.
When several orders are possible, use the following tie-breaking rule: whenever more than one task can be performed next at the same time, the smallest-numbered task must be performed first.