|
||||||||||
EscapeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 368 Accepted Submission(s): 169 Problem Description Given a maze of size n¡Ám. The rows are numbered 1, 2, ¡¤ ¡¤ ¡¤ , n from top to bottom while the columns are numbered 1, 2, ¡¤ ¡¤ ¡¤ , m from left to right, which means that (1, 1) is the top-left corner and that (n, m) is the bottom-right corner. And for each cell of size 1 ¡Á 1, it is either blank or blocked. There are a robots above the maze. For i-th robot, it is initially positioned exactly above the cell (1, pi), which can be described as (0, pi). And the initial moving direction of the robots are all downward, which can be written as (1, 0) in the vector form. Also, there are b exits below the maze. For i-th exit, it is positioned exactly below the cell (n, ei), which can be described as (n + 1, ei). Now, you want to let the robots escape from the maze by reaching one of the exits. However, the robots are only able to go straight along their moving directions and can¡¯t make a turn. So you should set some turning devices on some blank cells in the maze to help the robots make turns. There are 4 types of turning devices: For each cell, the number of turning devices on it can not exceed 1. And collisions between the robots are ignored, which allows multiple robots to visit one same cell even at the same time. You want to know if there exists some schemes to set turning devices so that all the a robots can reach one of the b exits after making a finite number of moves without passing a blocked cell or passing a turning device illegally or going out of boundary(except the initial position and the exit). If the answer is yes, print ¡°Yes¡± in a single line, or print ¡°No¡± if the answer is no. Input The first line contains one positive integer T (1 ¡Ü T ¡Ü 10), denoting the number of test cases. For each test case: The first line contains four positive integers n, m, a, b (1 ¡Ü n, m ¡Ü 100, 1 ¡Ü a, b ¡Ü m), denoting the number of rows and the number of columns in the maze, the number of robots and the number of exits respectively. Next n lines each contains a string of length m containing only ¡°0¡± or ¡°1¡±, denoting the initial maze, where cell (i, j) is blank if the j-th character in i-th string is ¡°0¡±, while cell (i, j) is blocked if the j-th character in i-th string is ¡°1¡±. The next line contains a integers pi (1 ¡Ü pi ¡Ü m), denoting the initial positions (0, pi) of the robots. The next line contains b integers ei (1 ¡Ü ei ¡Ü m), denoting the positions (n + 1, ei) of the exits. It is guaranteed that all pis are pairwise distinct and that all eis are also pairwise distinct. Output Output T lines each contains a string ¡°Yes¡± or ¡°No¡±, denoting the answer to corresponding test case. Sample Input
Sample Output
Hint Source | ||||||||||
|