How Many to Be Happy?

For each edge find the fewest edges to delete so that it lies in some minimum spanning tree, then sum those counts.

Medium7Minimum spanning treeGraphUnion-findGreedyInterviewNo attempts yetTime limit0.5sMemory limit512 MB

Problem

Let GG be a connected simple undirected graph in which every edge has a weight. Recall the minimum spanning tree (MST) problem. For each edge ee of GG, we ask how much GG must be modified before ee belongs to an MST of GG. Some MST of GG may already contain ee. In that case we say that ee is happy in GG, and we define H(e)=0H(e) = 0. It may also happen that no MST of GG contains ee. In that case we say that ee is unhappy in GG. We may then delete some edges of GG to obtain a connected graph GG' in which ee is happy. H(e)H(e) is the minimum number of edges to delete from GG so that ee is happy in the resulting graph GG'.

Figure E.1. A complete graph with 3 nodes.

The graph in Figure E.1 has 3 nodes and 3 edges. Its MST consists of the two edges with weights 1 and 2, so those two edges are happy in the graph. To make the edge of weight 3 happy, delete either one of the two happy edges.

Given a connected simple undirected graph GG, compute H(e)H(e) for every edge ee of GG and print the total sum.

Input

The first line contains two positive integers nn and mm, the number of vertices and the number of edges of the graph, where n100n \le 100 and m500m \le 500. The vertices are numbered from 1 to nn.

Each of the next mm lines contains three positive integers uu, vv, and ww, describing an edge between vertex uu and vertex vv with weight ww. Every weight is an integer between 1 and 500, inclusive.

The graph is connected, it has no self loop, and no two edges join the same pair of vertices.

Output

Print one integer SS, the sum of H(e)H(e) over all edges ee of GG.