#P6833. [Cnoi2020] 雷雨
[Cnoi2020] 雷雨
Background
Uneasy clouds begin to cover the sky.
Huge buildings creak in the strong wind.
Discordant sounds echo throughout Gensokyo.
— “Touhou Kishinjou ~ Double Dealing Character”.
On a stormy night with thunder and lightning, a bolt of lightning struck the Scarlet Devil Mansion by the Misty Lake and the Bamboo Forest of the Lost.
It seems that something big is about to happen, and Cirno is quietly thinking in her hut.
Problem Description
The vertical cross-section of Gensokyo can be abstracted as an rectangle.
Each cell has a resistance measurement value (a fictional concept) .
The lightning is emitted from on the thundercloud, and hits the Scarlet Devil Mansion and the Bamboo Forest of the Lost on the ground.
Since lightning is a natural creation, it will choose positions so that the total resistance measurement value is minimized. That is, the sum of resistance measurement values over the union of the two paths from to and is minimized.
So, when the resistance measurements at all positions are known, Cirno wants to know the minimum possible sum of resistance measurement values along the lightning’s paths.
Input Format
The first line contains five integers . .
The next lines each contain integers, representing the resistance measurement . The first row represents the thundercloud, and the last row represents the ground.
Output Format
One line with one integer, representing the answer.
5 5 1 2 4
1 8 1 6 6
1 1 1 2 4
8 3 1 2 2
1 2 1 9 1
1 0 9 1 1
15
Hint
Sample Explanation

As shown in the figure, the yellow lines are the lightning’s paths.
Constraints
For of the testdata, it is guaranteed that: , , .
Subtasks “This problem uses bundled tests”
- Subtask 1 (): .
- Subtask 2 (): .
- Subtask 3 (): .
- Subtask 4 (): .
- Subtask 5 (): No special constraints.
Translated by ChatGPT 5