#P6121. Farm Shutdown
Farm Shutdown
Farm Shutdown
FJ and his cows are planning a long journey, and to save money, FJ has decided to temporarily shut down his farm. The farm consists of \(N\) barns connected by \(M\) bidirectional roads. When a barn is closed, all roads connected to that barn are permanently removed.
FJ will close the barns one by one in a given order. At each moment (i.e. just before closing the next barn), he wants to know if the remaining open barns form a fully connected structure. A farm is considered fully connected if for any two open barns there exists a path connecting them using the remaining roads.
You are given the description of the farm and the order in which barns are closed. Determine the connectivity status of the farm at each moment.
inputFormat
The first line contains two integers \(N\) and \(M\) \((1 \leq N, M \leq 2 \times 10^5)\), representing the number of barns and roads respectively.
The next \(M\) lines each contain two integers \(u\) and \(v\) (1-indexed), indicating that there is a bidirectional road connecting barn \(u\) and barn \(v\).
The following \(N\) lines each contain a single integer representing the order in which the barns will be closed. The barns are listed one per line.
outputFormat
Output \(N\) lines. The \(i\)-th line should be YES
if the farm is fully connected before the \(i\)-th barn is closed, and NO
otherwise.
sample
4 3
1 2
2 3
3 4
3
4
1
2
YES
NO
YES
YES
</p>