Module: Practice with the queue


Problem

1 /3


Coloring

Theory Click to read/hide

An example algorithm
add a point to the queue (x0,y0)
remember the color of the starting point
until the queue is empty
  {
  take a point (x,y) from the queue
  if A[y][x] = color of starting point then
    {
    A[y][x] = 2;
    add a point to the queue (x-1,y)
    add a point to the queue (x+1,y)
    add a point to the queue (x,y-1)
    add a point to the queue (x,y+1)
    }
  }

Problem

The drawing is specified as a A matrix, in which the A[y][x] element defines the color of the pixel at the intersection of the y row and the column x. Recolor to 2 a one-color area starting at pixel (x0,y0).  

Input  
The first line specifies the size of the n square matrix (\(0<n<10\)). The second line contains the coordinates of the point (x0, y0) - two numbers separated by a space. Followed by n lines of n numbers in each line space (each number is not greater than 10).

Imprint
Output the resulting matrix after recoloring.
 
Examples
# Input Output
1 5
1 2
0 1 0 1 1
1 1 1 2 2
0 1 0 2 2
3 3 1 2 2
0 1 1 0 0
0 2 0 1 1
2 2 2 2 2
0 2 0 2 2
3 3 1 2 2
0 1 1 0 0