#P4150. [WC2009] 最短路问题
[WC2009] 最短路问题
Description
A grid is given, where each cell initially has a non-negative weight. There are two types of operations:
- Change the weight of a cell (the new weight is still non-negative).
- Query the weight of the shortest path between two cells.
Notes and task:
For any cell , its coordinates satisfy , . The Manhattan distance between cells and is defined as . An ordered sequence of cells is called a path from to if the Manhattan distance between any and is . Its weight is , where is the weight of cell . The shortest path between two cells and is a path from to with the minimum total weight.
Input Format
The first line contains an integer . The next lines each contain integers; on the -th line, the -th integer is the initial weight of cell . Then an integer follows, and the next lines each describe an operation.
There are two types of operations:
Type : "1 x y c" (without double quotes). Set the weight of cell to (, , ).
Type : "2 x_1 y_1 x_2 y_2" (without double quotes). Query the weight of the shortest path between cell and cell (, ).
Output Format
For each type operation, in the order they appear, output one line with one integer: the weight of the shortest path.
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
0
1
2
Hint
| Testdata ID | Testdata ID | ||||
|---|---|---|---|---|---|
2024/08/20: Added 3 sets of hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号