#K13621. Remove Redundant Tunnels
Remove Redundant Tunnels
Remove Redundant Tunnels
You are given an undirected graph with n locations and m tunnels. Each tunnel is represented by three integers u, v, and w, where u and v are the connected locations and w is the tunnel's length. Your task is to remove the redundant tunnels so that the remaining tunnels form a tree. Recall that a tree with n vertices has exactly \(n-1\) edges.
The removal is defined in such a way that you should keep a set of tunnels that connects all locations (i.e. a spanning tree) and the cost (sum of tunnel lengths) of the kept tunnels is determined based on a greedy approach (similar to Kruskal's algorithm). The number of tunnels removed is \(m - (n-1)\). Output the number of tunnels removed and the total length of the tunnels that remain.
inputFormat
The input is read from standard input. The first line contains two integers n and m separated by a space, where n is the number of locations and m is the number of tunnels. The next m lines each contain three integers u, v, and w, representing a tunnel between locations u and v with length w.
outputFormat
Print exactly two lines to standard output. The first line should be the number of tunnels removed. The second line should be the total length of the remaining tunnels in the tree.
## sample5 6
1 2 3
2 3 2
3 4 4
4 5 1
1 3 5
2 5 6
2
10
</p>