#K2181. Taco's Path Adventure
Taco's Path Adventure
Taco's Path Adventure
You are given an n x n grid representing a field. Each cell of the field contains a number: 0
indicates an open space and 1
indicates a rock.
Your task is to determine if there exists a path from the top-left cell to the bottom-right cell by moving only right or down. You cannot step on a rock. In mathematical terms, let \( F \) be an n x n matrix where \( F_{i,j} \in \{0,1\} \). Find if there exists a sequence of valid moves from \( (1,1) \) to \( (n,n) \) such that for each move \( (i,j) \rightarrow (i,j+1) \) or \( (i,j) \rightarrow (i+1,j) \), the cell value is 0
.
If a valid path exists, output Yes
; otherwise, output No
.
inputFormat
The input is given from stdin in the following format:
- An integer
n
representing the size of the grid. n
lines follow, each containingn
space-separated integers (each is either0
or1
) representing the grid.
outputFormat
Print a single line to stdout containing either Yes
if a valid path exists or No
otherwise.
1
0
Yes