atcoder#ABC219G. [ABC219G] Propagation
[ABC219G] Propagation
Score : points
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 .
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 : 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 .)
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