#!/usr/bin/env python3

import sys



def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):

    import numpy as np    

    from scipy.sparse import csr_matrix    

    from scipy.sparse.csgraph import floyd_warshall

    omat = csr_matrix((c+c, (a+b, b+a)), shape=(N+1, N+1), dtype=np.int32)

    smat = floyd_warshall(omat)

    return ((omat-smat) > 0).sum() // 2





# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    M = int(next(tokens))  # type: int

    a = [int()] * (M)  # type: "List[int]"

    b = [int()] * (M)  # type: "List[int]"

    c = [int()] * (M)  # type: "List[int]"

    for i in range(M):

        a[i] = int(next(tokens))

        b[i] = int(next(tokens))

        c[i] = int(next(tokens))

    print((solve(N, M, a, b, c)))



def test():

    import doctest

    doctest.testmod()



if __name__ == '__main__':

    #test()

    main()

#!/usr/bin/env python3

import sys



def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):

    import numpy as np    

    from scipy.sparse import csr_matrix    

    from scipy.sparse.csgraph import floyd_warshall

    omat = csr_matrix((c, (a, b)), shape=(N+1, N+1), dtype=np.int32)

    smat = floyd_warshall(omat, directed=False)

    return ((smat-omat) < 0).sum()





# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    M = int(next(tokens))  # type: int

    a = [int()] * (M)  # type: "List[int]"

    b = [int()] * (M)  # type: "List[int]"

    c = [int()] * (M)  # type: "List[int]"

    for i in range(M):

        a[i] = int(next(tokens))

        b[i] = int(next(tokens))

        c[i] = int(next(tokens))

    print((solve(N, M, a, b, c)))



def test():

    import doctest

    doctest.testmod()



if __name__ == '__main__':

    #test()

    main()

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import floyd_warshall

    omat = csr_matrix((c + c, (a + b, b + a)), shape=(N + 1, N + 1), dtype=np.int32)
    smat = floyd_warshall(omat)
    return ((omat - smat) > 0).sum() // 2


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    print((solve(N, M, a, b, c)))


def test():
    import doctest

    doctest.testmod()


if __name__ == "__main__":
    # test()
    main()

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import floyd_warshall

    omat = csr_matrix((c, (a, b)), shape=(N + 1, N + 1), dtype=np.int32)
    smat = floyd_warshall(omat, directed=False)
    return ((smat - omat) < 0).sum()


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    print((solve(N, M, a, b, c)))


def test():
    import doctest

    doctest.testmod()


if __name__ == "__main__":
    # test()
    main()

-    omat = csr_matrix((c + c, (a + b, b + a)), shape=(N + 1, N + 1), dtype=np.int32) -    smat = floyd_warshall(omat) -    return ((omat - smat) > 0).sum() // 2 +    omat = csr_matrix((c, (a, b)), shape=(N + 1, N + 1), dtype=np.int32) +    smat = floyd_warshall(omat, directed=False) +    return ((smat - omat) < 0).sum()