题目描述
Problem Description
Given a $n \times n \times n$ cube divided into $n^3$ unit cubes, some of which are obstacles and cannot be traversed.
Given the starting coordinates and the destination coordinates, each step allows moving from one unit cube to an adjacent (sharing a face) non-obstacle unit cube. Determine the minimum number of steps required to travel from the start to the destination.
Input Format
The first line contains an integer $n$.
The next line contains three integers $x_s, y_s, z_s$ representing the starting position.
The following line contains three integers $x_t, y_t, z_t$ representing the destination position.
Next, $n$ $n \times n$ matrices of $0$s and $1$s are provided, where the $i$-th matrix's $j$-th row and $k$-th column indicate whether $(j, k, i)$ is an obstacle (1 indicates an obstacle).
It is guaranteed that the starting and destination positions are not obstacles.
Output Format
Output a single integer representing the minimum number of steps. If it is not possible to reach the destination, output $-1$.
Sample Input and Output
Sample Input #1
2
1 1 1
1 1 2
00
10
01
00
Sample Output #1
1
Sample Input #2
3
2 3 1
1 1 1
000
010
000
111
111
111
111
111
111
Sample Output #2
3
Sample Input #3
3
2 1 1
3 2 2
000
010
110
010
001
001
101
110
000
Sample Output #3
3
Notes
Data Range
| Subtask | Points | Special Conditions |
|---|---|---|
| 1 | 7 | $n = 2$ |
| 2 | 16 | No obstacles |
| 3 | 22 | All cells with $z$ coordinates greater than 1 are obstacles |
| 4 | 25 | None |
For all data, $1 \le n \le 100$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分