#K14306. Maximum Travel Cost Reduction

    ID: 24105 Type: Default 1000ms 256MiB

Maximum Travel Cost Reduction

Maximum Travel Cost Reduction

You are given a network of N cities and M bidirectional roads. Each road connects two different cities with a given travel cost. Your task is to determine the maximum possible reduction in the travel cost by converting some roads into zero-cost roads. Mathematically, if the road cost is represented by \(l\), then the maximum reduction is given by the sum of all road costs: \(\sum_{i=1}^{M} l_i\), provided that there is more than one city and at least one road. If \(N = 1\) or \(M = 0\), the reduction is 0.

The input is given via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains two integers N and M, representing the number of cities and the number of roads respectively. The next M lines each contain three integers u, v, and l indicating that there is a road between city u and city v with a cost of l.

Input Format:

N M
u1 v1 l1
u2 v2 l2
... (M lines total)

outputFormat

Output a single integer, which is the maximum possible reduction in travel cost.

Output Format:

result
## sample
5 4
1 2 4
1 3 3
2 3 2
4 5 1
10