[Solution] Zero Path Codeforces Solution
You are given a grid with rows and columns. We denote the square on the -th () row and -th () column by and the number there by . All numbers are equal to or to .
You start from the square and can move one square down or one square to the right at a time. In the end, you want to end up at the square .
Is it possible to move in such a way so that the sum of the values written in all the visited cells (including and ) is ?
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains two integers and () — the size of the grid.
Each of the following lines contains integers. The -th integer on the -th line is ( or ) — the element in the cell .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print "YES" if there exists a path from the top left to the bottom right that adds up to , and "NO" otherwise. You can output each letter in any case.
No comments:
Post a Comment