#K50972. Taco Grid Navigation
Taco Grid Navigation
Taco Grid Navigation
You are given an \(N \times N\) grid consisting of characters '.' representing an empty cell and '#' representing an obstacle. Your task is to determine whether there is a path from the top-left corner (cell \(1,1\)) to the bottom-right corner (cell \(N,N\)) by moving only right or down through empty cells.
If such a path exists, output YES
; otherwise, output NO
. Note that a valid path cannot pass through cells with obstacles, and the starting and ending cells must be accessible (i.e. they must be '.').
You can approach this problem using depth-first search (DFS) or dynamic programming algorithms. Ensure that your solution reads input from stdin
and writes the result to stdout
.
inputFormat
The first line contains a single integer \(T\), the number of test cases. Each test case is described as follows:
- The first line contains an integer \(N\), the size of the grid.
- The next \(N\) lines each contain a string of length \(N\) consisting only of characters '.' and '#', representing the grid.
Input is read from stdin
.
outputFormat
For each test case, output a single line containing YES
if there exists a valid path from the top-left to the bottom-right corner (moving only right or down) or NO
otherwise. Output is printed to stdout
.
2
3
..#
.#.
...
4
....
..#.
.#..
...#
YES
NO
</p>