The following undirected network consists of seven vertices and twelve edges with a total weight of .
The same network can be represented by the matrix below.
However, it is possible to optimise the network by removing some edges and still ensure that all points on the network remain connected. The network which achieves the maximum saving is shown below. It has a weight of , representing a saving of from the original network.
containing a network with forty vertices, and given in matrix form, find the maximum saving which can be achieved by removing redundant edges whilst ensuring that the network remains connected.
First line contains two integers (Number of nodes) and (Number of edges) separated by a space.
Next lines contains 3 integers and representing an undirected edge betwen and who's weght is .
If there are edges between the same pair of nodes with different weights, they are to be considered as is, like multiple edges.