Sherlock Holmes is a renowned detective. His Scotland Yard colleagues often provide him with a set of evidence and ask for his help in solving the mysteries. After many years of practice, Holmes has gained an enormous amount of experience and already knows the causes for many common events, which, combined with his extraordinary deductive capabilities, enables him to solve cases in a matter of minutes, from the comfort of his chair.
Holmes' knowledge base can be modeled as a set of implications of the
form
Holmes is given a set
It's important to note that Holmes' knowledge is so mind-bogglingly huge that he knows all possible causes of events. In other words, there is no implication that is true, but not included in Holmes' knowledge base.
Many detective agencies would highly appreciate Holmes' one of a kind capabilities, so you were given a task to accomplish with a computer what is out of reach for ordinary mortals. Write a program to find all events that have certainly occurred based on the given implications and evidence collected by your colleague detectives.
Input Specification
The first line of input consists of three integers,
Each of the
Finally, each of the last
Output Specification
The first and only line of output should contain integers (in any order) representing events that have certainly occurred.
Sample Input 1
3 2 1
1 2
2 3
2
Sample Output 1
1 2 3
Sample Input 2
3 2 1
1 3
2 3
3
Sample Output 2
3
Explanation for Sample Output 2
The knowledge base contains implications
Sample Input 3
4 4 1
1 2
1 3
2 4
3 4
4
Sample Output 3
1 2 3 4
Explanation for Sample Output 3
Holmes doesn't know which event from the set
Comments