시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3 초 | 1024 MB | 17 | 13 | 12 | 80.000% |
The UltraNet company provides network connectivity for all cities in a country. For a pair of cities, they are either directly connected or indirectly connected. A city i and another city j are directly connected if a cable with a symmetrical bandwidth of bi,j = bj,i is wired between them. For two cities that are not directly connected, at least one path between the two cities exists. In the current UltraNet, more than one path is possibly available for a city pair.
The current UltraNet is perfectly working, while the maintenance fee of each cable is costly. Energy conservation is another concern. The energy consumption of a cable is proportional to its bandwidth. Therefore, the company has an optimization plan to reorganize the network with the policies in the following order:
Your task is to help UltraNet optimize the network and then output the sum of the bandwidths among all city pairs in the optimized network. For optimizing the following example, the three cables in dotted will be discarded. In the resulting network, the bottleneck is 3, the sum of bandwidths of the remaining four cables is 6 + 3 + 8 + 4 = 21, and the sum of the bandwidths among all city pairs is \(\sum_{i=1}{^n-1}\sum_{j=i+1}^{n}\)b'i,j = 6 + 4 + 6 + 3 + 4 + 8 + 3 + 4 + 3 + 3 = 44.
Each test case begins with two integers n and m, denoting numbers of cities and cables, respectively. Then, m lines will follow for specifying the m cables. Each of the m lines contains three positive integers, i, j, and bi,j, denoting that a cable with a bandwidth of bi,j directly connects the city pair (i, j), where the cities are numbered from 1 to n, and i < j since bi,j = bj,i. No more than one cable will be available between every city pair in the current network. In addition, the bandwidths of all cables are distinct; no two cables have the same bandwidth rating.
The output is a single integer that is the sum of the bandwidths of all city pairs in the optimized network.
3 3 1 2 5 1 3 6 2 3 8
20
5 7 1 2 6 1 3 10 1 4 12 2 4 8 2 5 3 3 4 4 4 5 2
44
5 5 2 5 1 1 2 2 2 3 4 1 3 5 2 4 6
24