Problem:
Score : 400 points

Problem Statement

You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.

The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.

Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).

A connected graph is a graph where there is a path between every pair of different vertices.

Find the number of the edges that are not contained in any shortest path between any pair of different vertices.

Constraints

2≤N≤100

N-1≤M≤min(N(N-1)/2,1000)

1≤a_i,b_i≤N

1≤c_i≤1000

c_i is an integer.

The given graph contains neither self-loops nor double edges.

The given graph is connected.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.

Sample Input 1

3 3
1 2 1
1 3 1
2 3 3

Sample Output 1

1

In the given graph, the shortest paths between all pairs of different vertices are as follows:

The shortest path from vertex 1 to vertex 2 is: vertex 1 → vertex 2, with the length of 1.

The shortest path from vertex 1 to vertex 3 is: vertex 1 → vertex 3, with the length of 1.

The shortest path from vertex 2 to vertex 1 is: vertex 2 → vertex 1, with the length of 1.

The shortest path from vertex 2 to vertex 3 is: vertex 2 → vertex 1 → vertex 3, with the length of 2.

The shortest path from vertex 3 to vertex 1 is: vertex 3 → vertex 1, with the length of 1.

The shortest path from vertex 3 to vertex 2 is: vertex 3 → vertex 1 → vertex 2, with the length of 2.

Thus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1.

Sample Input 2

3 2
1 2 1
2 3 1

Sample Output 2

0

Every edge is contained in some shortest path between some pair of different vertices.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;

namespace abc151_d
{
    class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().Split(' ');
            // 頂点数
            var n = int.Parse(items[0]);
            // 辺数
            var m = int.Parse(items[1]);
            // 最大の重み
            var max = 1000;

            // 辺の一覧(a<bしか使用しない)
            var lines = new int[n, n];
            // 通る点の一覧(最小の重みの格納用)
            var weights = new int[n, n];

            // まずは、1辺ごとの重みを入れて初期化(0は未計算)
            for (int i = 0; i < m; i++)
            {
                items = Console.ReadLine().Split(' ');
                var a = int.Parse(items[0]) - 1;
                var b = int.Parse(items[1]) - 1;
                var c = int.Parse(items[2]);
                SetWeight(lines, a, b, c);
                SetWeight(weights, a, b, c);
            }

            // Warshall-Floyd法というらしい。

            // これ、全頂点同士がつながってないと、ダメなのでは？2辺のものしか計算できないよね？
            // a-b-d-cがa-cより小さい(a-d,b-cはつながっていない)場合、a-b-d(つまりa-d)が計算済みでなければならないはず。
            // でも、このロジックでは、a-b b-d d-c → a-b-d a-c-dとなる。a-b-d-c(a-c-d前にa-c=a-b-dが評価済み)は計算されないはず。
            // 4 4
            // 1 2 1
            // 2 4 1
            // 4 3 1
            // 1 3 5

            // マイロジック→合わない
            {
                //// aから
                //for (int a = 0; a < n; a++)
                //{
                //    // bまで
                //    for (int b = a + 1; b < n; b++)
                //    {
                //        // 2辺以上の最短距離は、1+1以下にはなりえない
                //        var ab = GetWeight(weights, a, b, max);
                //        if (ab > 2)
                //        {
                //            // aとbの中間点
                //            for (int p = 0; p < n; p++)
                //            {
                //                if (a != p && b != p)
                //                {
                //                    var ap = GetWeight(weights, a, p, max);
                //                    var pb = GetWeight(weights, p, b, max);
                //                    // 最小値を記録
                //                    var weight = ap + pb;
                //                    if (weight < ab)
                //                    {
                //                        SetWeight(weights, a, b, weight);
                //                    }
                //                }
                //            }
                //        }
                //    }
                //}
            }

            // Warshall-Floyd法では、a=1-n b=1-nで計算するけど、これ、1辺を2回計算してるよね？
            // 後、pをforの最初にしてるのは、なんでだろう？

            // 試しに、Warshall-Floyd法どおりにやってみる
            // →これは、通る(あたりまえだけど)
            {
                //// aとbの中間点
                //for (int p = 0; p < n; p++)
                //{
                //    // aから
                //    for (int a = 0; a < n; a++)
                //    {
                //        // bまで
                //        for (int b = 0; b < n; b++)
                //        {
                //            // 2辺以上の最短距離は、1+1以下にはなりえない
                //            var ab = GetWeight(weights, a, b, max);
                //            if (ab > 2)
                //            {
                //                if (a != p && b != p)
                //                {
                //                    var ap = GetWeight(weights, a, p, max);
                //                    var pb = GetWeight(weights, p, b, max);
                //                    // 最小値を記録
                //                    var weight = ap + pb;
                //                    if (weight < ab)
                //                    {
                //                        SetWeight(weights, a, b, weight);
                //                    }
                //                }
                //            }
                //        }
                //    }
                //}
            }

            // 試しに、2回計算を通してみる→合わない
            // 試しに、pを先にしてみる

            // aとbの中間点
            for (int p = 0; p < n; p++)
            {
                // aから
                for (int a = 0; a < n; a++)
                {
                    // bまで
                    for (int b = a + 1; b < n; b++)
                    {
                        // 2辺以上の最短距離は、1+1以下にはなりえない
                        var ab = GetWeight(weights, a, b, max);
                        if (ab > 2)
                        {
                            if (a != p && b != p)
                            {
                                var ap = GetWeight(weights, a, p, max);
                                var pb = GetWeight(weights, p, b, max);
                                // 最小値を記録
                                var weight = ap + pb;
                                if (weight < ab)
                                {
                                    SetWeight(weights, a, b, weight);
                                }
                            }
                        }
                    }
                }
            }

            // 算出した重みより重い1辺があったら、それは最短距離でない
            var count = 0;
            for (int a = 0; a < n; a++)
            {
                for (int b = a + 1; b < n; b++)
                {
                    var line = GetWeight(lines, a, b, 0);
                    var weight = GetWeight(weights, a, b, max);
                    if (line > weight)
                    {
                        count++;
                    }
                }
            }

            Console.WriteLine($"{count}");
        }
        static void SetWeight(int[,] weights, int a, int b, int weight)
        {
            var x = a;
            var y = b;
            if (a > b)
            {
                x = b;
                y = a;
            }
            weights[x, y] = weight;
        }
        static int GetWeight(int[,] weights, int a, int b, int def)
        {
            var x = a;
            var y = b;
            if (a > b)
            {
                x = b;
                y = a;
            }
            var weight = weights[x, y];
            // 重みが未計算の時はデフォルト値を返す
            if (weight <= 0)
            {
                weight = def;
            }
            return weight;
        }
    }
}