#C2940. Path Existence in a Grid

    ID: 46312 Type: Default 1000ms 256MiB

Path Existence in a Grid

Path Existence in a Grid

Given an m×nm \times n grid where each cell contains either 0 (an empty cell) or 1 (an obstacle), determine whether there exists a path from the top-left corner (0,0)(0,0) to the bottom-right corner (m1,n1)(m-1,n-1). You may move in the four cardinal directions (up, down, left, right), but you cannot move through obstacles. All moves must remain within the bounds of the grid.

inputFormat

The input is read from stdin. The first line contains two integers mm and nn, representing the number of rows and columns respectively. Each of the following mm lines contains nn integers (either 0 or 1) separated by spaces, representing the grid.

outputFormat

Print to stdout a single line: "True" if there is a valid path from the top-left to the bottom-right, or "False" otherwise.## sample

3 3
0 0 1
0 1 0
0 0 0
True