Find the minimum number of spies to message so that every non-enemy spy receives the message and no enemy spy does, given a directed contact graph and a set of enemy spies.
Medium7GraphDFSDynamic programmingGreedyNo attempts yetTime limit2sMemory limit512 MBYou are a spy for the Benevolent Agent Protection Center (BAPC), and you have just obtained some top secret documents. You want every fellow spy in your organization to hear about them. Messaging all of them yourself is one option, but it takes far too long. Luckily the other spies have contact networks of their own, so they can pass the message on for you.
The problem is that enemy spies sit in the same network. An enemy spy who receives the message hands it straight to the enemy organization, so the message must never reach one. Luckily you know exactly who the traitors are, so you can avoid them.
There are two ways to send the information. A spy who receives a private message knows that it is confidential and tells nobody. A spy who receives a public message notifies every spy he or she can contact. Those spies do not treat it as confidential either, so they notify everyone they can contact in turn, and the message keeps spreading this way. A spy who already received the message earlier spreads it again on the next delivery. Because nobody may learn who the enemy spies are, you cannot tell a spy to skip some of the contacts.
If even one enemy spy receives the message, you have failed. Every spy who is not an enemy must receive it. Under both conditions, you want to message as few spies yourself as possible. How many do you have to message?
The first line contains three integers S, E and C. S (1≤S≤50000) is the number of spies in the network, not counting yourself. E (0≤E≤S) is the number of enemy spies, and C (0≤C≤100000) is the number of connections between spies.
Each of the next C lines contains two integers S1 and S2 (0≤S1<S, 0≤S2<S), meaning that spy S1 can contact spy S2. A connection works in one direction only. The same connection can appear more than once, and S1=S2 is allowed.
The last line contains the numbers of the E enemy spies, separated by spaces. If E=0, that line can be empty or missing.
You may assume that you can message every spy in the network directly.
Print one line with the minimum number of messages you have to send to other spies, counting both private and public messages.