#P6121. [USACO16OPEN] Closing the Farm G

[USACO16OPEN] Closing the Farm G

Description

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

There are NN barns on the farm, connected by MM bidirectional roads (1N,M2×1051 \leq N,M \leq 2 \times 10^5). To shut down the entire farm, FJ plans to close exactly one barn at a time. When a barn is closed, all roads connected to that barn are also closed and can never be used again.

FJ is interested in knowing whether his farm is "fully connected" at each moment (here, "moment" means the time before each barn is closed) — that is, starting from any open barn, it is possible to reach any other open barn. Note that after some moment, the entire farm may no longer be "fully connected".

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, indicating the index of the barn closed at the ii-th step.

Output Format

Output NN lines. Each line contains YES or NO, indicating whether the farm is fully connected at that moment.

The first line is the initial state. Line ii (2iN2 \leq i \leq N) is the state 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