luogu#P2820. 局域网

局域网

Background

In a certain local area network, there are nn computers. Due to negligence when setting up the LAN, the connections now form cycles. We know that if a LAN contains cycles, data will keep circulating within the cycle, causing network lag. Because the network cables connecting computers are different, some connections are not very smooth. We use f(i,j)f(i,j) to denote the smoothness between ii and jj; a smaller value of f(i,j)f(i,j) means a smoother connection between ii and jj, and f(i,j)=0f(i,j) = 0 means there is no cable between ii and jj.

Problem Description

Now we need to resolve the cycle problem. We will remove some cables so that the network contains no cycles, without changing the connectivity of the original graph's nodes, and the sum of f(i,j)f(i,j) over the removed cables is maximized. Please compute this maximum value.

Input Format

The first line contains two positive integers n,kn, k. The next kk lines each contain three positive integers i,j,mi, j, m, indicating that there is a cable between computers ii and jj with smoothness mm.

Output Format

A single positive integer: the maximum value of f(i,j)\sum f(i,j).

5 5
1 2 8
1 3 1
1 5 3
2 4 5
3 4 2

8

Hint

Constraints: For all testdata, it is guaranteed that 1n1001 \le n \le 100, 1f(i,j)10001 \le f(i,j) \le 1000.

Translated by ChatGPT 5