#abc219g. G - Propagation
G - Propagation
Score : points
问题描述
给定一个包含 个顶点和 条边的简单无向图。这 个顶点分别称为顶点 1、顶点 2、、顶点 。
对于每个 ,第 条边连接着顶点 和顶点 。
另外,对于每个 ,顶点 上写着一个整数 。
同时,还给出了 个查询。
对于每个 ,第 个查询由一个整数 表示。这个查询涉及以下操作:
- 让 等于顶点 上写的整数。
- 对于与顶点 相邻的所有顶点,将它们上面所写的整数替换为 。
这里,当存在一条连接顶点 和顶点 的边时,称它们是相邻的。
按照输入中给出的顺序,在所有查询处理完毕后,打印每个顶点上所写的整数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a simple undirected graph with vertices and edges. The vertices are called Vertex , Vertex , , Vertex .
For each , the -th edge connects Vertex and Vertex .
Additionally, for each , Vertex has an integer written on it.
You are also given queries.
For each , the -th query is represented as an integer . This query involves the following operation.
- Let be the integer written on Vertex .
- For every vertex adjacent to Vertex , replace the integer written on it with .
Here, Vertex and Vertex 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
- 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:
Output
Print the integers written on the vertices after all queries are processed, in the format below, with spaces in between.
Here, for each , denotes the integer written on Vertex .
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 : Vertex has the integer written on it, and the vertices adjacent to Vertex are Vertices and . Thus, the integers on Vertices and get replaced with .
- The second query : Vertex has the integer written on it, and the vertices adjacent to Vertex are Vertices and . Thus, the integers on Vertices and get replaced with .
- The third query : Vertex has the integer written on it, and the vertices adjacent to Vertex are Vertices , , and . Thus, the integers on Vertices , , and get replaced with . (Vertices and already have written on them, so the actual change takes place only on Vertex .)
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