J2 Cells

All submissions for this problem are available.
Little Anuj is in trouble.
He's trapped in a rectangular grid of cells.
Each cell has four doors.. One each to the north, south, east and west.
He has called home and asked for help, but it will take time to for his folks to get him out.
In the meantime, bored, he wants to determine for some pairs of cells whether or not it is possible to start from one and end at the other.
The only information he has is the number of rows and columns of cells and the status of each door.. whether closed or open.
All doors facing the outside world are closed.
Input
First line contains two numbers, m and n, where m= number of rows and n=number of columns of cells separated by a space. ( < 100)
The next m lines contain n1 numbers each, signifying the status of eastwest facing doors. ( 1 for open, 0 for closed )
The next m1 lines contain n numbers each, signifying the status of northsouth facing doors. ( 1 for open, 0 for closed )
For example, for m=2 and n=2, and the four cells as follows,
a b
c d
door between a and b open.
door between b and d open.
The input will be as follows
2 2
1 0
0 1
The next line will then contain the number of test cases for this scenario.
Each test case is given by four numbers, signifying index coordinates of starting cell and ending cell.
Output
For each test case, output 1 if there exists a path between the two cells and 0 if there doesn't, on a new line.
If the start and end cells are the same, output 1.
Example
Input: 2 5 1 1 1 0 1 0 0 0 1 0 0 1 0 9 0 0 0 1 1 2 0 0 1 4 1 3 0 2 0 3 1 0 1 1 1 0 0 4 0 0 1 3 0 0 1 4 1 3 0 3 Output: 1 0 0 1 1 0 1 0 1
Author:  credenz 
Tags  credenz 
Date Added:  28082012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, GO, NODEJS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 