#abc219g. G - Propagation

G - Propagation

Score : 600600 points

问题描述

给定一个包含 NN 个顶点和 MM 条边的简单无向图。这 NN 个顶点分别称为顶点 1、顶点 2、\ldots、顶点 NN

对于每个 i=1,2,,Mi = 1, 2, \ldots, M,第 ii 条边连接着顶点 uiu_i 和顶点 viv_i

另外,对于每个 i=1,2,,Ni = 1, 2, \ldots, N,顶点 ii 上写着一个整数 ii

同时,还给出了 QQ 个查询。
对于每个 i=1,2,,Qi = 1, 2, \ldots, Q,第 ii 个查询由一个整数 xix_i 表示。这个查询涉及以下操作:

  1. XX 等于顶点 xix_i 上写的整数。
  2. 对于与顶点 xix_i 相邻的所有顶点,将它们上面所写的整数替换为 XX

这里,当存在一条连接顶点 uu 和顶点 vv 的边时,称它们是相邻的。

按照输入中给出的顺序,在所有查询处理完毕后,打印每个顶点上所写的整数。

以上为通义千问 qwen-max 翻译,仅供参考。

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

Sample Input 1

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

Sample Output 1

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.)

Sample Input 2

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

Sample Output 2

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

update @ 2024/3/10 09:42:37