#DSU0000068. Đóng cửa nông trại (Closing the Farm (Gold))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đóng cửa nông trại (Closing the Farm (Gold))
Closing the Farm (Gold)
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
A farm has barns connected by undirected paths. The barns will be closed one at a time in a specified order. Closing a barn also removes all of its incident paths.
The farm is connected when every open barn can reach every other open barn. Determine whether this is true initially and after each of the first closures; in all these states at least one barn remains open.
A closed barn is no longer a vertex of the current graph. Thus, a path between two open barns cannot pass through a closed barn, even if roads previously led to it.
The closing order lists every barn exactly once. The first answer concerns the initially open farm; the last answer concerns the single remaining open barn. A graph with one vertex is connected.
Input
The first line contains . The next lines describe the paths. The last lines form a permutation of , the closing order.
Output
Print lines: the initial connectivity status, then the status after the first closures. Print YES for connected and NO otherwise.
Subtasks
- Subtask 1 (20 points): ; ; , ; the closing order is a permutation of .
- Subtask 2 (30 points): ; ; , ; the closing order is a permutation of .
- Subtask 3 (50 points): ; ; , ; the closing order is a permutation of .
Examples
Input
4 3
1 2
2 3
3 4
3
4
1
2
Output
YES
NO
YES
YES
Explanation
Initially all open barns are connected. After barn closes, barn is separated from the other open barns. After barn closes, barns and remain connected. A single remaining open barn is also connected.