#abc270f. F - Transportation
F - Transportation
Score : points
问题描述
在AtCoder共和国,有个岛屿。最初,没有任何一个岛屿拥有机场或港口,并且任意两个岛屿之间都没有道路相连。国王Takahashi计划为这些岛屿提供某种交通方式。具体来说,他可以按照任意顺序进行任意次数的以下操作:
- 选择一个整数,满足,并支付的成本在第个岛屿上建设机场。
- 选择一个整数,满足,并支付的成本在第个岛屿上建设港口。
- 选择一个整数,满足,并支付的成本建设一条双向连接第个岛屿和第个岛屿的道路。
Takahashi的目标是确保对于每一对不同的岛屿和,当可以按照任意顺序无限次执行以下动作时,可以从岛屿到达岛屿。
- 当岛屿和都有机场时,可以从岛屿前往岛屿。
- 当岛屿和都有港口时,可以从岛屿前往岛屿。
- 当岛屿和通过道路相连时,可以从岛屿前往岛屿。
请找出Takahashi需要支付的最小总成本以实现他的目标。
以上为通义千问 qwen-max 翻译,仅供参考。
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
- , 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.
Sample Input 1
4 2
1 20 4 7
20 2 20 3
1 3 5
1 4 6
Sample Output 1
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.
Sample Input 2
3 1
1 1 1
10 10 10
1 2 100
Sample Output 2
3
It is not mandatory to build all three types of facilities at least once.
Sample Input 3
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
Sample Output 3
160
update @ 2024/3/10 11:24:10