#C11235. Maze Path Finder

    ID: 40529 Type: Default 1000ms 256MiB

Maze Path Finder

Maze Path Finder

You are given a maze represented as a 2D grid of integers. Each cell of the maze is either open or a wall. The open cells are denoted by 0 and the walls by 1. You need to find a path from the upper left corner (cell (0, 0)) to the bottom-right corner (cell (n-1, m-1)).

The maze dimensions are given by two integers \(n\) and \(m\), where \(n\) is the number of rows and \(m\) is the number of columns. The goal is to reach from cell \((0, 0)\) to cell \((n-1, m-1)\) using only moves in the four cardinal directions: right, down, left, and up. If either the start or the goal cell is blocked, or there is no possible path, output -1.

It is guaranteed that when a valid path exists, the path found by a breadth-first search (BFS) is one of the shortest possible. The path should be output as a sequence of coordinates, one per line, with each coordinate in the format row col.

inputFormat

The first line contains two space-separated integers \(n\) and \(m\) which represent the number of rows and columns of the maze respectively. The following \(n\) lines each contain \(m\) space-separated integers (either 0 or 1) representing the maze.

It is guaranteed that all integers are 0 or 1.

outputFormat

If a path from cell \((0,0)\) to cell \((n-1, m-1)\) exists, output the coordinates of the cells along the path in order, one coordinate per line in the format row col. If there is no valid path, output -1.

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

0 1 0 2 1 2 2 2

</p>