#Q68. 「一本通 3.1 练习 1」新的开始
「一本通 3.1 练习 1」新的开始
Description
Developing the mining industry naturally requires mines first. Little FF spent one-thousandth of the wealth obtained from the last expedition to have mines dug on the island. However, he seems to have forgotten to consider the power supply issue for the mines...
To ensure the power supply, Little FF came up with two solutions:
- Build a power station on this mine at a cost of (the output power of the power station can supply any number of mines).
- Establish a power grid between this mine and another mine that already has a power supply, at a cost of .
Little FF hopes that you, the chief engineer of the "NewBe_One" project, can help him devise a plan to ensure power supply for all mines at the minimum cost.
Input Format
The first line contains an integer , representing the total number of mines.
Lines each contain an integer, where the -th number represents the cost of building a power station on the -th mine.
This is followed by an matrix , where represents the cost of establishing a power grid between the -th mine and the -th mine (the data ensures and ).
Output Format
Output only one integer, representing the minimum cost to ensure all mines receive sufficient power.
Sample 1
Little FF can choose to build a power station on mine and then establish power grids between all mines and it, with a total cost of .
4
5
4
4
3
0 2 2 2
2 0 3 3
2 3 0 4
2 3 4 0
9
Data Range and Hints
For of the data: ;
For of the data: .