#P1550. [USACO08OCT] Watering Hole G
[USACO08OCT] Watering Hole G
Description
Farmer John’s farm is short of water.
He decides to bring water to his fields. He can dig some wells and build channels between fields to connect them for water supply. Digging a well in field costs units. Connecting field and field costs (with ) units.
Find the minimum amount of money FJ needs so that every field is either connected to a field that has water or has its own well.
Input Format
The first line contains an integer .
The next lines each contain an integer .
The next lines each contain integers; the -th number in the -th line is the cost to connect field and field .
Output Format
Output the minimum cost.
4
5
4
4
3
0 2 2 2
2 0 3 3
2 3 0 4
2 3 4 0
9
Hint
Constraints: For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号