#P8427. [COI 2020] Paint
[COI 2020] Paint
Description
You must have used the one-click fill tool in drawing software. If we look at it on the pixel level: if all pixels in a large connected component have the same color, then recoloring one pixel will recolor all pixels in that connected component.
Now you are given an pixel image and recoloring operations:
- Recolor to color .
Output the entire image after all recoloring operations.
Input Format
The first line contains two integers , representing the size of the pixel image.
The next lines each contain integers, representing the initial colors of the image.
Line contains an integer , representing the number of operations.
The next lines each contain three integers , representing one recoloring operation.
Output Format
Output lines, each containing integers, representing the recolored pixel image.
12 11
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1
1 1 1 0 0 0 0 0 1 1 1
1 1 0 0 0 0 0 0 0 1 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 2 0 0 0 1 1
0 1 1 0 0 2 0 0 1 1 0
0 0 1 1 0 0 0 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
2
5 5 3
6 2 4
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 4 4 4 1 1 1 1
1 1 1 4 4 4 4 4 1 1 1
1 1 4 4 4 4 4 4 4 1 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 4 4 4 4 4 4 1
1 1 4 4 4 2 4 4 4 1 1
0 1 1 4 4 2 4 4 1 1 0
0 0 1 1 4 4 4 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
4 4
1 0 1 3
1 3 2 2
3 3 1 2
2 2 1 3
3
1 2 3
3 2 1
4 2 3
1 1 1 3
1 1 2 2
1 1 1 2
3 3 1 3
6 6
1 2 1 2 2 2
3 1 2 1 3 1
3 3 2 3 2 2
2 3 1 3 3 2
3 3 3 3 3 3
2 3 2 2 2 1
4
6 2 2
3 5 2
3 2 3
1 2 3
1 3 1 2 2 2
3 1 3 1 3 1
3 3 3 3 3 3
3 3 1 3 3 3
3 3 3 3 3 3
3 3 3 3 3 1
Hint
Explanation for Sample 1
Assume is white, is red, is blue, is green, and is yellow, as shown in the figure below:

Constraints
This problem uses bundled testdata.
- Subtask 1 (8 pts): , .
- Subtask 2 (9 pts): , , .
- Subtask 3 (31 pts): , , and there are only colors and .
- Subtask 4 (52 pts): , .
For of the testdata, , , , and the color range is .
Notes
Translated from Croatian Olympiad in Informatics 2020 A Paint。
Translated by ChatGPT 5
京公网安备 11011102002149号