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

#SRD0000108. Lan truyền giá trị (Propagation)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lan truyền giá trị (Propagation)

Propagation

Source: AtCoder Version: Phuoc Hung OJ Extended

Problem Statement

You are given a simple undirected graph with NN vertices and MM edges. Vertices are numbered 11 through NN. Initially, vertex ii contains the integer ii.

There are QQ operations. Operation tt specifies a vertex xtx_t and works as follows:

  1. Read the value XX currently written at vertex xtx_t, immediately before the operation.
  2. Simultaneously replace the values at all vertices adjacent to xtx_t by XX.

The value at xtx_t itself is not changed by this operation, since the graph has no self-loops. If xtx_t has no neighbors, the operation has no effect. Process all operations in the order given.

Output the values at all NN vertices after the final operation.

Input

  • First line: N M Q.
  • Next MM lines: u_i v_i, an undirected edge. The graph has no self-loops or duplicate edges.
  • Finally, QQ integers x1,…,xQx_1,\ldots,x_Q, separated by spaces or line breaks.

Output

Print NN space-separated integers A1,A2,…,ANA_1,A_2,\ldots,A_N, where AiA_i is the final value at vertex ii.

Subtasks

  • Subtask 1 (15 points): 1≤N≤501\le N\le 50, 0≤M≤min⁡(100,N(N−1)/2)0\le M\le\min(100,N(N-1)/2), 1≤Q≤1501\le Q\le 150; 1≤ui,vi,xt≤N1\le u_i,v_i,x_t\le N; no self-loops or multiple edges.
  • Subtask 2 (20 points): 1≤N≤10001\le N\le 1000, 0≤M≤min⁡(2000,N(N−1)/2)0\le M\le\min(2000,N(N-1)/2), 1≤Q≤50001\le Q\le 5000; 1≤ui,vi,xt≤N1\le u_i,v_i,x_t\le N; no self-loops or multiple edges.
  • Subtask 3 (25 points): 1≤N≤150001\le N\le 15000, 0≤M≤min⁡(18000,N(N−1)/2)0\le M\le\min(18000,N(N-1)/2), 1≤Q≤400001\le Q\le 40000; 1≤ui,vi,xt≤N1\le u_i,v_i,x_t\le N; no self-loops or multiple edges.
  • Subtask 4 (40 points): 1≤N≤2000001\le N\le 200000, 0≤M≤min⁡(200000,N(N−1)/2)0\le M\le\min(200000,N(N-1)/2), 1≤Q≤2000001\le Q\le 200000; 1≤ui,vi,xt≤N1\le u_i,v_i,x_t\le N; no self-loops or multiple edges.

Examples

Example 1

Input

5 6 3
4 2
4 3
1 2
2 3
4 5
1 5
1 3 4

Output

1 3 3 3 3

Explanation

Initially, vertices contain (1,2,3,4,5)(1,2,3,4,5). Processing vertex 11 writes 11 to vertices 22 and 55, yielding (1,1,3,4,1)(1,1,3,4,1). Processing vertex 33 writes 33 to vertices 22 and 44, yielding (1,3,3,3,1)(1,3,3,3,1). Finally, vertex 44 now contains 33 and writes it to neighbors 2,3,52,3,5, giving (1,3,3,3,3)(1,3,3,3,3).

Example 2

Input

14 14 8
7 4
13 9
9 8
4 3
7 2
13 8
12 8
11 3
6 3
7 14
6 5
1 4
10 13
5 2
2 6 12 9 1 10 5 4

Output

1 6 1 1 6 6 1 9 9 10 11 12 10 14

Explanation

In the second example, the selected vertices are 2,6,12,9,1,10,5,42,6,12,9,1,10,5,4 in this order. Each selection propagates its current value to its neighbors. After the eighth operation, the values at vertices 11 through 1414 are 1 6 1 1 6 6 1 9 9 10 11 12 10 14. Vertex 1414, for example, is never overwritten, so it retains its original value 1414.