#P5954. [JSOI2013] 侦探 JYY
[JSOI2013] 侦探 JYY
Problem Description
In the world of JSOI, there are different events (numbered from to ), and clues. Each clue corresponds to an ordered pair , meaning that if event happens, it will cause event to happen.
Note: Clues are one-way. That is, if happens, it does not mean that must have happened.
Clues are transitive. That is, if there are clues and , then if happens, it will cause to happen.
At the same time, since the world is reasonable, any event will never, through some clues, cause event itself to happen.
Also, the entire world contains only these clues. We do not assume that some events happen out of nowhere (just as Holmes would never believe a strange murder case is due to divine punishment). Specifically, for an event , if happens and there exists some event that could cause to happen, then at least one event that could cause to happen must have happened.
Now, given the clues in the world and events that are known to have happened, determine which events must have happened for sure.
Input Format
The first line contains three integers separated by spaces: , , and .
The next lines each contain two integers and , representing the clue , satisfying .
The next lines each contain a distinct integer between and , representing the events that are known to have happened.
Output Format
Output one line containing at least strictly increasing positive integers separated by spaces, representing the events that JYY can deduce must have happened based on the clues and the known events.
3 2 1
1 3
2 3
3
3
4 4 1
1 2
1 3
2 4
3 4
4
1 2 3 4
Hint
Sample Explanation
In the first sample, since either event or event happening would cause event to happen, we cannot determine which of the two events actually happened.
In the second sample, since event happened, at least one of event and event happened. No matter which one happened, we can conclude that event happened.
Finally, since event happened, we can deduce that all events must have happened.
Constraints
For of the data, 。
Translated by ChatGPT 5