#abc364g. G - Last Major City

G - Last Major City

Score : 600600 points

问题陈述

AtCoder国家由NN个城市和MM条道路连接,可以通过穿越一些道路在任意两个城市之间旅行。城市从11NN编号,道路从11MM编号。道路ii双向连接城市AiA_iBiB_i

由于国家交通量的增加,计划扩建一些道路。目前,还没有道路被扩建,扩建道路ii的成本是CiC_i

由于一次性扩建所有道路很困难,计划首先指定KKNN个城市作为主要城市,然后进行最少必要的扩建工作,以确保可以通过仅使用扩建的道路在任意两个主要城市之间旅行。已经决定城市1,2,,K11, 2, \dots, K-1将是主要城市,但最后一个主要城市尚未决定。

对于每个i=K,K+1,,Ni=K, K+1, \dots, N,回答以下问题:

  • 如果指定城市ii作为最后一个主要城市,确保可以通过仅使用扩建的道路在任意两个主要城市之间旅行所需的扩建工作的最小总成本是多少?

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

The Country of AtCoder consists of NN cities and MM roads connecting them, and one can travel between any two cities by traversing some roads. The cities are numbered from 11 to NN, and the roads are numbered from 11 to MM. Road ii connects cities AiA_i and BiB_i 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 ii is CiC_i.

Since it is difficult to expand all roads at once, the plan is to first designate KK out of the NN 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 1,2,,K11, 2, \dots, K-1 will be major cities, but the last major city has not yet been decided.

For each i=K,K+1,,Ni=K, K+1, \dots, N, answer the following question:

  • If city ii 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

  • 2N40002 \leq N \leq 4000
  • N1M8000N-1 \leq M \leq 8000
  • 2Kmin(N,2\leq K \leq \min(N,\,1010))
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • 1Ci1091 \leq C_i \leq 10^9
  • 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:

NN MM KK

A1A_1 B1B_1 C1C_1

A2A_2 B2B_2 C2C_2

\vdots

AMA_M BMB_M CMC_M

Output

Print NK+1N-K+1 lines. The ll-th line (1lNK+1)(1 \leq l \leq N-K+1) should contain the answer to the question for i=l+K1i=l+K-1, 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 i=3i=3 and i=4i=4, respectively. The colored circles represent the major cities, and the colored thick lines represent the roads that are expanded in an optimal solution.

  • For i=3i=3, expanding roads 44 and 55 results in a total cost of 2+1=32+1=3, which is the minimum.
  • For i=4i=4, expanding roads 11, 44, and 55 results in a total cost of 3+2+1=63+2+1=6, 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.

}