PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000068. Đóng cửa nông trại (Closing the Farm (Gold))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đó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 NN barns connected by MM 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 N−1N-1 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 N,MN,M. The next MM lines describe the paths. The last NN lines form a permutation of 1,2,…,N1,2,\ldots,N, the closing order.

Output

Print NN lines: the initial connectivity status, then the status after the first N−1N-1 closures. Print YES for connected and NO otherwise.

Subtasks

  • Subtask 1 (20 points): 2≤N≤302\le N\le 30; 1≤M≤1201\le M\le 120; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the closing order is a permutation of 1,…,N1,\ldots,N.
  • Subtask 2 (30 points): 2≤N≤30002\le N\le 3000; 1≤M≤60001\le M\le 6000; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the closing order is a permutation of 1,…,N1,\ldots,N.
  • Subtask 3 (50 points): 2≤N≤2000002\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the closing order is a permutation of 1,…,N1,\ldots,N.

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 33 closes, barn 44 is separated from the other open barns. After barn 44 closes, barns 11 and 22 remain connected. A single remaining open barn is also connected.