#K8571. Taco Grid Path Finder
Taco Grid Path Finder
Taco Grid Path Finder
You are given a grid of dimensions \(n \times m\) where each cell contains either 0 or 1. A 0 indicates an empty cell and a 1 indicates an obstacle. Your task is to find a path from the top‐left cell \((0,0)\) to the bottom‐right cell \((n-1, m-1)\) by moving only in the four cardinal directions (up, down, left, right) through empty cells. If a valid path exists, output the sequence of coordinates along the path. Otherwise, output -1.
Note: The input is read from standard input (stdin) and the output must be printed to standard output (stdout).
Constraints: You can assume that \(1 \leq n, m \leq 1000\). The top-left and bottom-right cells are always considered as start and destination respectively, but may be blocked.
inputFormat
The first line contains two space-separated integers \(n\) and \(m\), representing the number of rows and columns in the grid respectively. The next \(n\) lines each contain \(m\) space-separated integers (0 or 1) representing the grid.
outputFormat
If a path exists, output each coordinate of the path on a separate line in order, where each line contains two space-separated integers (row and column). If no path exists, output -1.
## sample2 2
0 1
0 0
0 0
1 0
1 1
</p>