Skywalker Maze
Skywalker is trapped inside a maze, and he needs your help!
Given a maze \(N \times M\), the location of Skywalker and Princess Leia, you need to inform Skywalker if he could reach Leia without having to encounter any stormtroopers.
The following is an example maze of \(3 \times 4\), with 0 being empty space,
S
stormtroopers, L
being Leia, K
being Skywalker.
SSSS
K000
SSSL
Skywalker at each time can move to the four adjacent areas, as well as jumping across a stormtrooper. Skywalker can jump vertically and horizontally, but not diagonal. So in the above example he will be able to reach Leia.
In the following example maze of \(1 \times 5\), Skywalker can still reach Leia since he can simply do a Jedi Jump:
K0S0L
But the Jedi jump cannot go over multiple stormtroopers:
K0SS0L
In this case, Skywalker will not be able to reach Leia. Curse you Darth Vader!
Input Specification
The first line will contain a single number \(K\) (\(K < 100\)), which is the number of test cases.
The following \(K\) test cases will each contain 2 parts, with the first line containing 2 integers \(N,M\) (\(0 < N,M < 100\)).
The next \(N\) lines will each \(M\) characters with no space, describing a maze.
Output Specification
The output should contain \(K\) lines, each with Yes
indicating Skywalker can
reach Leia, No
indicating cannot reach Leia
Sample Input
3
3 4
SSSS
K000
SSSL
1 5
K0S0L
3 4
SSSS
K00S
SSSL
Sample Output
Yes
Yes
No
Comments