#P2121. 拆地毯
拆地毯
Description
There are key areas in the venue, and different key areas are connected by undirected "carpets." Each carpet is represented by three integers , , and , where and are the indices of the two key areas connected by this carpet, and 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 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 carpets.
Input Format
The first line contains three positive integers , , and .
Each of the next lines contains three positive integers , , and .
Output Format
Output a single positive integer, the maximum possible sum of beauty values of these carpets.
5 4 3
1 2 10
1 3 9
2 3 7
4 5 3
22
Hint
Choosing carpets , , and gives a beauty sum of .
If you choose carpets , , and , although the sum can reach , key areas , , and would form a cycle, which is not allowed.
Constraints: .
Translated by ChatGPT 5
京公网安备 11011102002149号