atcoder#ABC270F. [ABC270F] Transportation
[ABC270F] Transportation
Score : points
Problem Statement
The Republic of AtCoder has islands. Initially, none of the islands has an airport or harbor, and there is no road between any two of them. Takahashi, the king, will provide some means of transportation between these islands. Specifically, he can do the following operations any number of times in any order.
- Choose an integer such that and pay a cost of to build an airport on island .
- Choose an integer such that and pay a cost of to build a harbor on island .
- Choose an integer such that and pay a cost of to build a road that bidirectionally connects island and island .
Takahashi's objective is to make it possible, for every pair of different islands and , to reach island from island when one can perform the following actions any number of times in any order.
- When islands and both have airports, go from island to island .
- When islands and both have harbors, go from island to island .
- When islands and are connected by a road, go from island to island .
Find the minimum total cost Takahashi needs to pay to achieve his objective.
Constraints
- $1\leq A_i
- , if .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum total cost Takahashi needs to pay to achieve his objective.
4 2
1 20 4 7
20 2 20 3
1 3 5
1 4 6
16
Takahashi will build the following infrastructure.
- Pay a cost of to build an airport on island .
- Pay a cost of to build an airport on island .
- Pay a cost of to build a harbor on island .
- Pay a cost of to build a harbor on island .
- Pay a cost of to build a road connecting island and island .
Then, the objective will be achieved at a cost of . There is no way to achieve the objective for a cost of or less, so should be printed.
3 1
1 1 1
10 10 10
1 2 100
3
It is not mandatory to build all three types of facilities at least once.
7 8
35 29 36 88 58 15 25
99 7 49 61 67 4 57
2 3 3
2 5 36
2 6 89
1 6 24
5 7 55
1 3 71
3 4 94
5 6 21
160