#K2951. Grid Path Finder

    ID: 24850 Type: Default 1000ms 256MiB

Grid Path Finder

Grid Path Finder

You are given a grid with n rows and m columns. Each cell in the grid is either passable, represented by '0', or an obstacle, represented by '1'. Your task is to determine whether there is a valid path from the top-left corner (cell (0, 0)) to the bottom-right corner (cell (n-1, m-1)).

You can move in the four cardinal directions: up, down, left, and right. A move is valid if the destination cell is within the grid bounds and is not an obstacle.

The problem can be mathematically described by the following conditions:

  • For any cell indices \(i, j\), it must hold that \(0 \le i < n\) and \(0 \le j < m\).
  • A cell \(grid[i][j]\) is passable if \(grid[i][j] = '0'\) and blocked if \(grid[i][j] = '1'\).

If a path exists, output Yes; otherwise, output No.

inputFormat

The input is read from standard input (stdin) and has the following format:

n m
row1
row2
...
row_n

Here, n and m are integers denoting the number of rows and columns. Each row is a string of length m consisting only of the characters '0' and '1'.

outputFormat

Output a single line to standard output (stdout) containing Yes if a valid path exists, or No if it does not.

## sample
4 4
0010
1000
0110
0000
Yes