#C6590. Escape from the Grid
Escape from the Grid
Escape from the Grid
Given a maze represented as an n × m grid, where each cell is either open (denoted by 0) or blocked (denoted by 1), determine if there exists a path from the top-left corner to the bottom-right corner. You can move only in four directions: up, down, left, or right.
Formally, given a grid (G) of size (n \times m), check if there exists a sequence of moves from cell ((0, 0)) to cell ((n-1, m-1)) that passes only through open cells. The starting and ending cells are included in the path.
inputFormat
The first line contains two integers (n) and (m), representing the dimensions of the grid. Each of the next (n) lines contains (m) space-separated integers (either 0 or 1), representing the grid cells (0 for open, 1 for blocked).
outputFormat
Print “true” (without quotes) if there exists a valid path from the top-left to the bottom-right cell. Otherwise, print “false”.## sample
5 5
0 1 0 0 0
0 1 0 1 0
0 0 0 1 0
0 1 1 1 0
0 0 0 0 0
true