P5954 [JSOI2013] Detective JYY
Description
In the world of JSOI, there are $N$ different events (numbered from $1$ to $N$), and $M$ clues. Each clue corresponds to an ordered pair $(x,y)$, meaning that if event $x$ happens, it will cause event $y$ to happen.
**Note: Clues are one-way. That is, if $y$ happens, it does not mean that $x$ must have happened.**
Clues are transitive. That is, if there are clues $(x,y)$ and $(y,z)$, then if $x$ happens, it will cause $z$ to happen.
At the same time, since the world is reasonable, any event $x$ will never, through some clues, cause event $x$ itself to happen.
Also, the entire world contains only these $M$ 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 $x$, if $x$ happens and there exists some event that could cause $x$ to happen, then at least one event that could cause $x$ to happen must have happened.
Now, given the $M$ clues in the world and $D$ 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: $N$, $M$, and $D$.
The next $M$ lines each contain two integers $x$ and $y$, representing the clue $(x,y)$, satisfying $1\leq x,y\leq N$.
The next $D$ lines each contain a distinct integer between $1$ and $N$, representing the events that are known to have happened.
Output Format
Output one line containing at least $D$ strictly increasing positive integers separated by spaces, representing the events that JYY can deduce must have happened based on the $M$ clues and the $D$ known events.
Explanation/Hint
### Sample Explanation
In the first sample, since either event $1$ or event $2$ happening would cause event $3$ to happen, we cannot determine which of the two events actually happened.
In the second sample, since event $4$ happened, at least one of event $2$ and event $3$ happened. No matter which one happened, we can conclude that event $1$ happened.
Finally, since event $1$ happened, we can deduce that all $4$ events must have happened.
### Constraints
For $100\%$ of the data, $1\leq D\leq N\leq 10^3,1\leq M\leq 10^5$。
Translated by ChatGPT 5