#K95222. Alice and Bob's Grid Meeting
Alice and Bob's Grid Meeting
Alice and Bob's Grid Meeting
Alice starts at the top-left corner of a grid, while Bob starts at the bottom-right corner. The grid consists of cells which are either open (denoted by '.') or blocked (denoted by '#'). Both Alice and Bob can move one step at a time in the four cardinal directions (up, down, left, right), but they can only move onto open cells. The task is to determine whether there exists a path for both such that their regions of reachable cells overlap (i.e. they can meet).
In other words, if we let \(R_A\) be the set of all cells reachable by Alice starting from cell (0,0) and \(R_B\) be the set of all cells reachable by Bob starting from cell (n-1, m-1), then they can meet if and only if \(R_A \cap R_B \neq \emptyset\).
You need to print YES
if they can meet, and NO
otherwise.
inputFormat
The input is read from stdin and has the following format:
T n m s1 s2 ... sn ... (repeated for each test case)
Here, T is the number of test cases. For each test case, the first line contains two integers n and m denoting the number of rows and columns of the grid respectively. The following n lines each contain a string of length m consisting of characters '.' (open cell) and '#' (blocked cell).
outputFormat
For each test case, output a single line to stdout containing either YES
if Alice and Bob can meet, or NO
if they cannot.
1
3 3
...
..#
...
YES
</p>