#K14856. Flood Fill Grid Painting

    ID: 24227 Type: Default 1000ms 256MiB

Flood Fill Grid Painting

Flood Fill Grid Painting

You are given a grid of size \(m \times n\) where each cell contains an integer representing its color. The task is to perform a flood fill operation starting from a specified cell located at (row, col) and change the color of that region to a new given color.

A region is defined as all cells that are connected to the starting cell horizontally or vertically (not diagonally) and have the same initial color as the starting cell. If the new color is the same as the original color, no changes are made.

Your program should read input from stdin and output the final grid to stdout.

inputFormat

The input will be given as follows:

  1. The first line contains two integers \(m\) and \(n\): the number of rows and columns of the grid.
  2. The next \(m\) lines each contain \(n\) space-separated integers representing the grid.
  3. The last line contains three integers: row, col, and new_color.

Here, \(0 \leq row < m\) and \(0 \leq col < n\). The integers in the grid and \(new_color\) can be any valid integer.

outputFormat

Output the modified grid after performing the flood fill. The grid should be printed with \(m\) lines, each line containing \(n\) space-separated integers.

## sample
3 3
1 1 1
1 1 0
1 0 1
1 1 2
2 2 2

2 2 0 2 0 1

</p>