#C1651. Even Sum Path
Even Sum Path
Even Sum Path
Given a 2D grid of integers, determine whether there exists a valid path from the top-left cell to the bottom-right cell such that the sum of the values along the path is even. You are only allowed to move either right or down from a cell. Formally, given a grid (A) of size (n \times m), starting at (A_{0,0}) and ending at (A_{n-1,m-1}), check if there is a sequence of moves where each move is either (\rightarrow) or (\downarrow) such that the total sum (\sum A_{i,j}) along the path satisfies (\sum A_{i,j} \equiv 0 \pmod{2}).
If such a path exists, output “YES”; otherwise, output “NO”.
inputFormat
The input is given via standard input. The first line contains an integer (T) denoting the number of test cases. Each test case begins with a line containing two integers (n) and (m) — the number of rows and columns in the grid. This is followed by (n) lines, each containing (m) space-separated integers representing the grid.
outputFormat
For each test case, output a single line containing either “YES” if there exists a valid path whose sum is even, or “NO” otherwise. The output should be printed to standard output.## sample
1
2 2
1 2
3 4
YES
</p>