GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 18 June 2022

[Solution] Zero Path Codeforces Solution


C. Zero Path
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a grid with n rows and m columns. We denote the square on the i-th (1in) row and j-th (1jm) column by (i,j) and the number there by aij. All numbers are equal to 1 or to 1.

You start from the square (1,1) 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 (n,m).

Is it possible to move in such a way so that the sum of the values written in all the visited cells (including a11 and anm) is 0?


Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t104). Description of the test cases follows.

Solution Click Below:-  CLICK HERE

The first line of each test case contains two integers n and m (1n,m1000)  — the size of the grid.

Each of the following n lines contains m integers. The j-th integer on the i-th line is aij (aij=1 or 1)  — the element in the cell (i,j).

It is guaranteed that the sum of nm over all test cases does not exceed 106.







Output

For each test case, print "YES" if there exists a path from the top left to the bottom right that adds up to 0, and "NO" otherwise. You can output each letter in any case.

No comments:

Post a Comment