Problem1292--walk in maze

1292: walk in maze

[Creator : ]
Time Limit : 1 sec  Memory Limit : 128 MB

Description

Define a two-dimensional array int b[n][n], and it represents a maze.The number 1 represents the wall,and the number 0 reprensents the walking path.You are only allowed to walk vertically or horizontally in the maze.You need to figure out if you can walk from one starting point to one terminal point(the starting point and the terminal point are setted by yourself).

Input

The input consists of several groups of test cases.
The first line of every cases is a integer n,which represents a n*n maze.
Then you should input n rows and n columns,which represent the layout of the maze.
The following line consists of two integers x1,y1,which represent the starting point's abscissa and ordinate.
The last line consists of two integers x2,y2,which represent the terminal point's abscissa and ordinate.
(The starting point and the terminal point must be the walking path,not the wall)

Output

If you can walk from the starting point to the terminal point,output the number of steps you need to walk.(One adjacent movement is one step.)
If you can't walk from the starting point to the terminal point,output"Unable to pass through"(Don't output the "").

Sample Input Copy

5
0 1 0 0 0
0 1 0 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
1 1
5 5
5
0 1 0 1 0
0 1 0 1 0
0 0 0 0 0
0 1 1 1 1
0 0 0 1 0
1 1
5 5

Sample Output Copy

9
Unable to pass through

HINT

搜索--dfs、bfs

Source/Category

POJ