#P3144. Closing the Farm

    ID: 16402 Type: Default 1000ms 256MiB

Closing the Farm

Closing the Farm

Farmer John (FJ) is planning a long journey with his cows and intends to temporarily close his farm to save money. The farm consists of N barns connected by M bidirectional roads. When FJ closes a barn, all roads incident to that barn will also be closed and can no longer be used.

FJ is interested in knowing, before each barn closure, whether the farm is fully connected – that is, whether all open barns are mutually reachable. Note that once a barn is closed, it will no longer contribute to connectivity, and over time the farm may cease to be fully connected.

The barns are numbered from 1 to N. You are given a list of the M roads and then a closing order of the N barns. For each step (i.e. just before closing the barn at that step), output whether the remaining open barns form a single connected component.

The connectivity condition can be mathematically expressed as: if we let A be the set of open barns at some time and comp(a) denote the size of the connected component containing barn a, then the farm is fully connected if and only if for any open barn a,

\(\displaystyle comp(a)=|A|\).

inputFormat

The first line contains two integers N and M (1 \(\leq N, M \leq 3000\)), representing the number of barns and the number of roads.

The next M lines each contain two integers u and v (1 \(\leq u,v \leq N\)), representing a bidirectional road connecting barns u and v.

The following N lines describe the closing order. Each line contains a single integer, indicating the barn to be closed at that step. The barns are numbered from 1 to N.

outputFormat

Output N lines. The i-th line (starting from i=1) should be YES if the farm is fully connected before the i-th closing, or NO otherwise.

sample

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

NO YES YES

</p>