There is No Alternative
Time limit3sMemory limit256 MB
Count the bridges that appear in every minimum-cost set connecting all islands and report their total cost.
- Level
Medium7 of 10
- Topics
- Minimum spanning tree, Union-find, DFS
- Solved
- No attempts yet
Problem
ICPC (Isles of Coral Park City) is made up of several islands. The residents asked the city to build bridges between the islands so that they no longer depend on boats, and they require that every island be reachable from every other island over one or more bridges.
The mayor picked a number of island pairs and had a construction company estimate the cost of a bridge for each pair. He now has to decide which bridges to build so that all the islands are connected and the total construction cost is as small as possible.
Several different sets of bridges can reach that same minimum total cost. The mayor decided to start by building only the bridges that appear in every minimum cost set. Such a bridge is called a no alternative bridge.
Given the candidate bridges and their costs, write a program that reports how many no alternative bridges there are and what their construction costs add up to.
Input
The input consists of a single test case.
N M
S1 D1 C1
.
.
.
SM DM CM
The first line contains the number of islands and the number of island pairs that a bridge may be built between. Each island is identified by an integer from to .
Each of the next lines contains three integers , and (), meaning that building the bridge between island and island costs .
, , , and . No two bridges connect the same pair of islands, that is, if and , then . If all the candidate bridges are built, every island is reachable from every other island over one or more bridges.
Output
Print the number of no alternative bridges and the sum of their construction costs on one line, separated by a space.