You are given a
- Change the label of a lattice point to another non-negative integer.
- Find the shortest path between two lattice points.
Here the length of a path is defined as the sum of labels of all lattice points the path passes through, and two lattice points are adjacent if they have Manhattan distance 1 (i.e.
Input Specification
The first line of input will contain a single integer,
The next 6 lines will contain
The following line will contain a single integer,
The operations will be one of the following:
1 x y c
: The label of is changed to , where , , .2 x1 y1 x2 y2
: Output the length of the shortest path between and , as defined above, where , .
Output Specification
For each type 2 operation, output the length of the shortest path between
Sample Input
Copy
5
0 0 1 0 0
0 1 0 1 0
0 2 0 1 0
0 1 1 1 0
0 0 0 0 0
1 1 1 1 1
5
2 1 2 1 4
1 1 1 10000
2 1 2 1 4
1 2 3 10000
2 1 2 3 3
Sample Output
Copy
0
1
2
Constraints
Case | ||
---|---|---|
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | ||
9 | ||
10 |
Comments