题目描述
Problem Description
Translated from COCI 2010.03.20 T5 "HOLMES"
There are $D$ events, numbered from $1$ to $D$.
Sherlock Holmes has $M$ inferences of the form $A \rightarrow B$, indicating that "if event $A$ occurs, then event $B$ will definitely occur." Note that this does not imply "if $A$ does not occur, then $B$ will definitely not occur."
These $M$ inferences can form chain structures, such as $A \rightarrow B \rightarrow C$, but they will never form loops, like $A \rightarrow B \rightarrow C \rightarrow \dots \rightarrow A$.
Given that events $S_1 \ldots S_N$ will occur, determine which events will definitely occur.
Update: The original problem statement was unclear (or my Chinese is too poor), so I added a sentence to explain Sample 1. For an event $X$, if there are inferences $Y_1 \rightarrow X$, $Y_2 \rightarrow X$, then "event $X$ will definitely occur" if and only if "event $Y_1$ will definitely occur" or "event $Y_2$ will definitely occur"…
Input Format
The first line contains three integers: $D$, $M$, and $N$.
The next $M$ lines each contain two integers, representing an inference $A_i, B_i$.
The next $N$ lines each contain one integer $S_i$.
Output Format
Output a single line containing several integers, representing the events that will definitely occur.
Please output them in increasing order of their numbers, as the problem setter is too lazy to write a special judge.
Sample Input and Output
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
Sample Input #3
4 4 1
1 2
1 3
2 4
3 4
4
Sample Output #3
1 2 3 4
Sample Input #4
4 4 1
1 3
2 3
1 4
2 4
3
Sample Output #4
3 4
Notes
Sample Explanation #2
Knowing only that event 3 occurs, we cannot deduce whether it was caused by event 1 or event 2.
Sample Explanation #3
Event 4 occurs, so at least one of events 2 and 3 must occur.
Either way, their condition is that event 1 must occur.
Since event 1 must occur, events 2 and 3 must also occur.
Sample Explanation #4
Event 3 occurs, so at least one of events 1 and 2 must occur.
If either event 1 or event 2 occurs, event 4 will definitely occur.
Data Range and Hints
$1 \le D \le 1000$, $1 \le M \le 10^5$, $1 \le N$, $X_i$, $A_i$, $B_i \le D$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分