Prison Break
Time limit2sMemory limit512 MB
Given a grid of '+' and '*' huts where movement is allowed only between huts of the same symbol, decide whether the entry hut can reach the exit hut.
Problem
A prison is built as a labyrinth. The labyrinth is made of huts, and every hut is marked + or *. Two huts are neighbors when they share a side. From a + hut the prisoner moves only to a neighboring + hut, and from a * hut only to a neighboring * hut.
The labyrinth is a rectangle of length and width . A hut is identified by a horizontal position and a vertical position. Horizontal positions run from to starting at the left, and vertical positions run from to starting at the bottom.
Every hut of the labyrinth is an entry hut, but there is only one exit hut. You are given the labyrinth, the entry hut where the prisoner stands, and the exit hut. Decide whether the prisoner can reach the exit hut.
Input
The first line contains the number of test cases .
The first line of each test case contains six natural numbers , , , , , separated by spaces.
- is the length of the labyrinth and is its width.
- and are the horizontal and vertical positions of the entry hut where the prisoner stands.
- and are the horizontal and vertical positions of the exit hut.
Then follow lines of characters each. Every character is + or *. The lines are given from the top of the labyrinth downward, so the -th line describes the huts whose vertical position is .
, , , , , and the sum of over all test cases is at most .
Output
For each prison print YES if the prisoner can escape and NO otherwise, one answer per line.