atcoder#ABC219G. [ABC219G] Propagation

[ABC219G] Propagation

Score : 600600 points

Problem Statement

You are given a simple undirected graph with NN vertices and MM edges. The NN vertices are called Vertex 11, Vertex 22, \ldots, Vertex NN. For each i=1,2,,Mi = 1, 2, \ldots, M, the ii-th edge connects Vertex uiu_i and Vertex viv_i. Additionally, for each i=1,2,,Ni = 1, 2, \ldots, N, Vertex ii has an integer ii written on it.

You are also given QQ queries. For each i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th query is represented as an integer xix_i. This query involves the following operation.

  1. Let XX be the integer written on Vertex xix_i.
  2. For every vertex adjacent to Vertex xix_i, replace the integer written on it with XX.

Here, Vertex uu and Vertex vv are said to be adjacent when there is an edge connecting them.

Print the integer written on each vertex after all queries are processed in the order they are given from input.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0Mmin(2×105,N(N1)/2)0 \leq M \leq \min(2 \times 10^5, N(N-1)/2)
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1ui,viN1 \leq u_i, v_i \leq N
  • 1xiN1 \leq x_i \leq N
  • The given graph is simple. In other words, it has no self-loops and no multi-edges.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM QQ

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

x1x_1 x2x_2 \ldots xQx_Q

Output

Print the integers written on the vertices after all queries are processed, in the format below, with spaces in between. Here, for each i=1,2,,Ni = 1, 2, \ldots, N, AiA_i denotes the integer written on Vertex ii.

A1A_1 A2A_2 \ldots ANA_N

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

Each query involves the following operation.

  • The first query (x1=1)(x_1 = 1): Vertex 11 has the integer 11 written on it, and the vertices adjacent to Vertex 11 are Vertices 22 and 55. Thus, the integers on Vertices 22 and 55 get replaced with 11.
  • The second query (x2=3)(x_2 = 3): Vertex 33 has the integer 33 written on it, and the vertices adjacent to Vertex 33 are Vertices 22 and 44. Thus, the integers on Vertices 22 and 44 get replaced with 33.
  • The third query (x3=4)(x_3 = 4): Vertex 44 has the integer 33 written on it, and the vertices adjacent to Vertex 44 are Vertices 22, 33, and 55. Thus, the integers on Vertices 22, 33, and 55 get replaced with 33. (Vertices 22 and 33 already have 33 written on them, so the actual change takes place only on Vertex 55.)
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
1 6 1 1 6 6 1 9 9 10 11 12 10 14