#K9521. Drawing a Path in a Grid
Drawing a Path in a Grid
Drawing a Path in a Grid
You are given an n × m grid consisting of integers 0 and 1. A cell containing 0 is walkable, whereas a cell with 1 is blocked. Starting from the top-left cell at position \((0,0)\), you can only move either to the right (i.e. \((i, j+1)\)) or downward (i.e. \((i+1, j)\)). Your task is to determine whether there exists a valid path from the top-left cell to the bottom-right cell at position \((n-1, m-1)\).
If a valid path exists, output YES
; otherwise, output NO
.
inputFormat
The first line contains two integers, \(n\) and \(m\), representing the number of rows and columns of the grid, respectively.
Each of the next \(n\) lines contains \(m\) space-separated integers (each either 0 or 1) representing a row of the grid.
outputFormat
Output a single line containing either YES
if a valid path exists, or NO
if it does not.
3 3
0 1 0
0 0 0
0 1 0
YES
</p>