import numpy as np

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix

N, M = list(map(int, input().split()))

a, b, c = [], [], []

for i in range(M):

    ai, bi, ci = list(map(int, input().split()))

    a.append(ai-1)

    b.append(bi-1)

    c.append(ci)



G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int)

D, P = floyd_warshall(G, directed=False, return_predecessors=True)

edges = []

for i in range(N):

    for j in range(N):

        if P[j][i] < 0 or i == P[j][i]:

            continue

        edges.append((min(i, P[j][i]), max(i, P[j][i])))

edges = list(set(edges))

print((M - len(edges)))

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix

fn = lambda: [int(x) for x in input().split()]

N, M = fn()

data, row_idx, col_idx = [0]*M, [0]*M, [0]*M

for i in range(M):

    ai, bi, ci = fn()

    row_idx[i] = ai - 1

    col_idx[i] = bi - 1

    data[i] = ci



G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int)

D, P = floyd_warshall(G, directed=False, return_predecessors=True)

edges = []

for i in range(N):

    for j in range(N):

        Pji = P[j][i]

        if Pji < 0 or i == Pji:

            continue

        edges.append((min(i, Pji), max(i, Pji)))

edges = set(edges)

print((M - len(edges)))
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M = list(map(int, input().split()))
a, b, c = [], [], []
for i in range(M):
    ai, bi, ci = list(map(int, input().split()))
    a.append(ai - 1)
    b.append(bi - 1)
    c.append(ci)
G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int)
D, P = floyd_warshall(G, directed=False, return_predecessors=True)
edges = []
for i in range(N):
    for j in range(N):
        if P[j][i] < 0 or i == P[j][i]:
            continue
        edges.append((min(i, P[j][i]), max(i, P[j][i])))
edges = list(set(edges))
print((M - len(edges)))

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

fn = lambda: [int(x) for x in input().split()]
N, M = fn()
data, row_idx, col_idx = [0] * M, [0] * M, [0] * M
for i in range(M):
    ai, bi, ci = fn()
    row_idx[i] = ai - 1
    col_idx[i] = bi - 1
    data[i] = ci
G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int)
D, P = floyd_warshall(G, directed=False, return_predecessors=True)
edges = []
for i in range(N):
    for j in range(N):
        Pji = P[j][i]
        if Pji < 0 or i == Pji:
            continue
        edges.append((min(i, Pji), max(i, Pji)))
edges = set(edges)
print((M - len(edges)))

-import numpy as np -N, M = list(map(int, input().split())) -a, b, c = [], [], [] +fn = lambda: [int(x) for x in input().split()] +N, M = fn() +data, row_idx, col_idx = [0] * M, [0] * M, [0] * M -    ai, bi, ci = list(map(int, input().split())) -    a.append(ai - 1) -    b.append(bi - 1) -    c.append(ci) -G = csr_matrix((c, (a, b)), shape=(N, N), dtype=int) +    ai, bi, ci = fn() +    row_idx[i] = ai - 1 +    col_idx[i] = bi - 1 +    data[i] = ci +G = csr_matrix((data, (row_idx, col_idx)), shape=(N, N), dtype=int) -        if P[j][i] < 0 or i == P[j][i]: +        Pji = P[j][i] +        if Pji < 0 or i == Pji: -        edges.append((min(i, P[j][i]), max(i, P[j][i]))) -edges = list(set(edges)) +        edges.append((min(i, Pji), max(i, Pji))) +edges = set(edges)