#P1141. Alternating Maze Traversal
Alternating Maze Traversal
Alternating Maze Traversal
You are given an maze consisting only of the digits and . If you are in a cell with value , you can move to any one of its adjacent cells (up, down, left, right) that contains a . Similarly, if you are in a cell with value , you can move to any one of its adjacent cells that contains a .
Your task is to determine how many cells can be reached (including the starting cell) if you start from a specified cell.
inputFormat
The input begins with an integer , denoting the size of the maze. The next line contains two integers and (0-indexed) which represent the starting cell. This is followed by lines, each containing space-separated integers (each either or ) representing the maze.
outputFormat
Output a single integer indicating the total number of cells reachable from the starting cell (including the starting cell itself) according to the alternating move rules.
sample
3
0 0
0 1 0
1 0 1
0 1 0
9