Hide

Problem F
Heavy Edges

/problems/heavyedges/file/statement/en/img-0001.png
The T-Fast near KTH. (2014)

Björn went to the local grocery store, the T-Fast, and came back carrying an extremely heavy... graph?

In a graph, an edge $e$ is said to be a heavy edge if there exists a simple cycle that contains $e$ in which $e$ is the heaviest edge (equal or heavier weight than all other edges in the cycle).

Björn would like to know how heavy the graph he brought back is. Given a connected, undirected, weighted graph, find the number of heavy edges.

Input

The input will describe the graph that Björn brought back.

The first line of input contains the two integers $N$ and $M$ ($1 \leq N,M \leq 5 \cdot 10^5$), the number of vertices and edges in the graph.

The following $M$ lines each contain three integers $u_i, v_i, w_i$ ($1 \leq u_i, v_i \leq N$, $1 \leq w_i \leq M$), meaning that an edge goes between vertices $u_i$ and $v_i$ of weight $w_i$.

The graph will always be connected, and contains no self-loops or multiple edges. This implies that $u_i \neq v_i$ for all $i = 1,\dots ,M$, and there is at most one edge between each pair of nodes.

Output

Print an integer: the number of heavy edges in the graph.

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

Group

Points

Constraints

$1$

$30$

All $w_i$ are unique.

$2$

$70$

No additional constraints.

Sample Input 1 Sample Output 1
5 7
1 2 7
2 3 6
3 1 5
3 4 4
4 2 3
2 5 2
5 4 1
3
Sample Input 2 Sample Output 2
5 5
1 2 3
2 3 1
3 4 4
4 5 1
5 1 5
1
Sample Input 3 Sample Output 3
5 6
1 2 6
2 3 6
3 1 6
3 4 1
4 5 1
5 1 1
3
Sample Input 4 Sample Output 4
5 4
1 2 3
2 3 3
3 4 3
4 5 3
0

Please log in to submit a solution to this problem

Log in