#K14226. Path to the Bottom-Right Corner
Path to the Bottom-Right Corner
Path to the Bottom-Right Corner
You are given an \(n \times m\) grid where each cell is either free (0) or blocked (1). You can only move in two directions: down and right.
Your goal is to determine whether there exists a path from the top-left corner (cell (1,1)) to the bottom-right corner (cell \((n, m)\)) that avoids all blocked cells.
If such a path exists, output "Yes"; otherwise, output "No".
inputFormat
The input is read from stdin
and consists of multiple test cases. The first line contains an integer T representing the number of test cases. Each test case starts with two space-separated integers n and m which denote the dimensions of the grid. Following that, there are n lines each containing m space-separated integers (0 or 1) representing the grid.
outputFormat
For each test case, print "Yes" if there exists a valid path from the top-left corner to the bottom-right corner; otherwise, print "No". Each answer should be output on its own line to stdout
.
2
3 3
0 0 0
0 1 0
0 0 0
3 3
0 1 0
1 1 0
0 0 0
Yes
No
</p>