#P3144. [USACO16OPEN] Closing the Farm S

[USACO16OPEN] Closing the Farm S

Description

FJ and his cows are planning to leave town for a long trip, and FJ wants to temporarily shut down his farm to save some money.

The farm has NN barns connected by MM bidirectional roads (1N,M30001 \leq N,M \leq 3000). To close the entire farm, FJ plans to close one barn at a time. When a barn is closed, all roads incident to that barn are closed and can no longer be used.

FJ is interested in knowing, at each time (here, “time” means the moment just before each barn is closed), whether his farm is “fully connected” — that is, from any open barn, it is possible to reach any other open barn. Note that from some time onward, the entire farm may cease to be fully connected.

Description

Input Format

The first line contains two integers N,MN,M.

The next MM lines each contain two integers u,vu,v (1u,vN1 \leq u,v \leq N), describing a road connecting barns uu and vv.

The last NN lines each contain one integer, where the ii-th line gives the index of the ii-th barn to be closed.

Output Format

Output NN lines, each containing YES or NO, indicating whether the farm is fully connected at that time.

Print the initial status on the first line. On line ii (2iN2 \leq i \leq N), print the status after the (i1)(i-1)-th barn has been closed.

4 3
1 2
2 3
3 4
3
4
1
2
YES
NO
YES
YES

Hint

Translated by ChatGPT 5