#K301. Path Finding in a Grid

    ID: 24863 Type: Default 1000ms 256MiB

Path Finding in a Grid

Path Finding in a Grid

You are given a grid of size m×nm \times n, where each cell is either free (0) or blocked (1). The goal is to determine if there exists a path from the top-left cell (0,0)(0,0) to the bottom-right cell (m1,n1)(m-1,n-1) by moving only right or down. Note that the starting and destination cells must be free. If a valid path exists, print "YES"; otherwise, print "NO".

inputFormat

The input is read from standard input. 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 space-separated integers (0 or 1) indicating the state of each cell in the grid.

outputFormat

Output a single line to standard output containing either "YES" if there exists a path from the top-left to the bottom-right corner, or "NO" otherwise.## sample

3 3
0 1 0
0 0 0
1 1 0
YES