#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 barns on the farm, connected by bidirectional roads (). 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 .
The next lines each contain two integers (), describing a road connecting barns and .
The last lines each contain one integer, indicating the index of the barn closed at the -th step.
Output Format
Output 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 () is the state after the -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
京公网安备 11011102002149号