#abc364g. G - Last Major City
G - Last Major City
Score : points
问题陈述
AtCoder国家由个城市和条道路连接,可以通过穿越一些道路在任意两个城市之间旅行。城市从到编号,道路从到编号。道路双向连接城市和。
由于国家交通量的增加,计划扩建一些道路。目前,还没有道路被扩建,扩建道路的成本是。
由于一次性扩建所有道路很困难,计划首先指定个个城市作为主要城市,然后进行最少必要的扩建工作,以确保可以通过仅使用扩建的道路在任意两个主要城市之间旅行。已经决定城市将是主要城市,但最后一个主要城市尚未决定。
对于每个,回答以下问题:
- 如果指定城市作为最后一个主要城市,确保可以通过仅使用扩建的道路在任意两个主要城市之间旅行所需的扩建工作的最小总成本是多少?
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
The Country of AtCoder consists of cities and roads connecting them, and one can travel between any two cities by traversing some roads. The cities are numbered from to , and the roads are numbered from to . Road connects cities and bidirectionally.
Due to increasing traffic in the country, some roads are planned to be expanded. Currently, no roads have been expanded, and the cost to expand road is .
Since it is difficult to expand all roads at once, the plan is to first designate out of the cities as major cities and perform the minimum necessary expansion work so that one can travel between any two major cities using only expanded roads. It has already been decided that cities will be major cities, but the last major city has not yet been decided.
For each , answer the following question:
- If city is designated as the last major city, what is the minimum total cost of the expansion work required to ensure that one can travel between any two major cities using only expanded roads?
Constraints
- One can travel between any two cities by traversing some roads.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the question for , as an integer.
Sample Input 1
4 5 3
1 4 3
3 4 4
1 2 4
2 3 2
1 3 1
Sample Output 1
3
6
In the above figure, circles with numbers represent cities with those numbers, and lines with numbers represent roads with the cost of expansion being that number. The left and right figures correspond to the cases and , respectively. The colored circles represent the major cities, and the colored thick lines represent the roads that are expanded in an optimal solution.
- For , expanding roads and results in a total cost of , which is the minimum.
- For , expanding roads , , and results in a total cost of , which is the minimum.
Sample Input 2
4 3 2
2 4 28
1 4 56
1 3 82
Sample Output 2
84
82
56
Sample Input 3
6 12 4
2 6 68
2 5 93
4 6 28
2 4 89
3 6 31
1 3 10
1 2 53
3 5 1
3 5 74
3 4 22
4 5 80
3 4 35
Sample Output 3
85
64
94
There may be multiple roads connecting the same pair of cities.