#P2121. 拆地毯

拆地毯

Description

There are nn key areas in the venue, and different key areas are connected by mm undirected "carpets." Each carpet is represented by three integers uu, vv, and ww, where uu and vv are the indices of the two key areas connected by this carpet, and ww is its beauty value.

Since the ceremony has ended, the laid carpets must be removed. To follow the principle of thrift, the organizers are allowed to keep at most KK carpets, and in the graph formed by the kept carpets, there must be only one way to travel between any two mutually reachable points. In other words, the new graph must have no cycles. Now the organizers ask you to compute the maximum possible sum of beauty values of at most KK carpets.

Input Format

The first line contains three positive integers nn, mm, and KK.

Each of the next mm lines contains three positive integers uu, vv, and ww.

Output Format

Output a single positive integer, the maximum possible sum of beauty values of these KK carpets.

5 4 3
1 2 10
1 3 9
2 3 7
4 5 3
22

Hint

Choosing carpets 11, 22, and 44 gives a beauty sum of 10+9+3=2210 + 9 + 3 = 22.

If you choose carpets 11, 22, and 33, although the sum can reach 10+9+7=2610 + 9 + 7 = 26, key areas 11, 22, and 33 would form a cycle, which is not allowed.

Constraints: 1n,m,K1051 \le n, m, K \le 10^5.

Translated by ChatGPT 5