#C11322. Labyrinth Pathfinding

    ID: 40626 Type: Default 1000ms 256MiB

Labyrinth Pathfinding

Labyrinth Pathfinding

You are given a rectangular labyrinth represented as a grid of size \(n \times m\). Each cell in the grid is either free, represented by '0', or blocked, represented by '1'. The entrance is located at the top-left cell (cell \((1,1)\)) and the exit is at the bottom-right cell (cell \((n,m)\)). You are allowed to move only to the right or down.

Your task is to determine if there exists a valid path from the entrance to the exit that only passes through free cells.

Note: If either the entrance or the exit is blocked, then no path exists.

inputFormat

The input is read from stdin and has the following format:

T
n1 m1
row1
row2
... (n1 rows total)
n2 m2
row1
row2
... (n2 rows total)
...

Here, T is the number of test cases. For each test case, the first line contains two integers \(n\) and \(m\), representing the number of rows and columns of the labyrinth. The next \(n\) lines each contain a string of length \(m\) representing a row of the labyrinth.

outputFormat

For each test case, print a single line to stdout with either "Yes" if there exists a path from the entrance to the exit, or "No" if there does not exist such a path.

## sample
2
3 4
0000
0110
0000
3 3
010
111
001
Yes

No

</p>