#K48782. Matrix Path Checker

    ID: 28497 Type: Default 1000ms 256MiB

Matrix Path Checker

Matrix Path Checker

Given an \(N \times M\) matrix consisting of 0s (blocked cells) and 1s (open cells), determine whether there exists a path from the top-left corner to the bottom-right corner. From any cell, you are only allowed to move either right or down. The path can only traverse cells with a value of 1.

If such a path exists, output "YES"; otherwise, output "NO". This problem requires you to implement an efficient search (e.g. depth-first search) while respecting the movement constraints.

inputFormat

The first line contains two integers \(N\) and \(M\) representing the number of rows and columns respectively. The following \(N\) lines each contain \(M\) integers (either 0 or 1) separated by spaces, representing the matrix.

outputFormat

Output a single string: "YES" if a valid path from the top-left to the bottom-right exists, or "NO" otherwise.

## sample
3 3
1 0 0
1 1 0
0 1 1
YES