#C14857. Pathfinding in a Grid
Pathfinding in a Grid
Pathfinding in a Grid
You are given a grid represented by an matrix , where each element is either 0 or 1. A cell with a value of 0 is free, while a cell with a value of 1 is blocked. Your task is to determine whether there exists a valid path from the top-left corner (cell ) to the bottom-right corner (cell ). You can only move in two directions: right or down. Note that if the starting or ending cell is blocked (i.e. equal to 1), then no valid path exists.
Input Constraints:
The first line of input contains two integers and , representing the number of rows and columns, respectively. The following lines each contain integers (either 0 or 1) separated by spaces, representing the grid.
Note: The allowed moves from any free cell are to the cell (right) or (down).
inputFormat
Input is given from standard input (stdin). The first line contains two integers and , the number of rows and columns in the grid. Each of the next lines contains space-separated integers which are either 0 (free) or 1 (blocked).
outputFormat
Output to standard output (stdout) a single line containing either 'true' if there exists a valid path from the top-left corner to the bottom-right corner, or 'false' otherwise.## sample
3 3
0 0 0
0 1 0
0 0 0
true
</p>