Santa's assistant, Hatsune Miku, has been tasked with minimizing the cost of a light-up toy! The toy can be described as lights numbered to connected by wires, each connecting two lights and with a cost . Santa wishes to use some subset of wires to connect all lights with minimum total cost. However, there are often multiple ways to do so, and Hatsune Miku doesn't know which configuration Santa will choose. As such, she decides that her task should be to remove all wires that could never be in a minimum configuration. Can you figure out the number of wires that she must keep (i.e. the number of wires that could potentially be part of a configuration that connects all the lights with minimum total cost)?
More formally, you are tasked with finding the number of edges in a graph that could potentially be part of its Minimum Spanning Tree.
Constraints
It is guaranteed that the graph is connected.
Input Specification
The first line contains two integers and : the number of nodes and edges respectively.
The next lines each contain 3 integers , , and , indicating an edge between and of weight
Output Specification
One integer, the number of edges that could potentially be part of a Minimum Spanning Tree.
Sample Input
5 6
1 2 2
1 3 2
1 4 4
1 5 4
5 4 4
4 2 5
Sample Output
5
Sample Explanation
The graph looks like this:
Two potential MST's are drawn below:
From this, it should be clear that 1 2
, 1 3
, 1 4
, 1 5
, and 5 4
can all be used in the MST. However, 4 2
cannot; so, there are edgess that could potentially be part of an MST.
Comments