#SRD0000108. Lan truyền giá trị (Propagation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lan truyền giá trị (Propagation)
Propagation
Source: AtCoder Version: Phuoc Hung OJ Extended
Problem Statement
You are given a simple undirected graph with vertices and edges. Vertices are numbered through . Initially, vertex contains the integer .
There are operations. Operation specifies a vertex and works as follows:
- Read the value currently written at vertex , immediately before the operation.
- Simultaneously replace the values at all vertices adjacent to by .
The value at itself is not changed by this operation, since the graph has no self-loops. If has no neighbors, the operation has no effect. Process all operations in the order given.
Output the values at all vertices after the final operation.
Input
- First line:
N M Q. - Next lines:
u_i v_i, an undirected edge. The graph has no self-loops or duplicate edges. - Finally, integers , separated by spaces or line breaks.
Output
Print space-separated integers , where is the final value at vertex .
Subtasks
- Subtask 1 (15 points): , , ; ; no self-loops or multiple edges.
- Subtask 2 (20 points): , , ; ; no self-loops or multiple edges.
- Subtask 3 (25 points): , , ; ; no self-loops or multiple edges.
- Subtask 4 (40 points): , , ; ; 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 . Processing vertex writes to vertices and , yielding . Processing vertex writes to vertices and , yielding . Finally, vertex now contains and writes it to neighbors , giving .
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 in this order. Each selection propagates its current value to its neighbors. After the eighth operation, the values at vertices through are 1 6 1 1 6 6 1 9 9 10 11 12 10 14. Vertex , for example, is never overwritten, so it retains its original value .