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: Wrong Answer)

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]);

            // 辺の一覧(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]);
                var b = int.Parse(items[1]);
                var c = int.Parse(items[2]);
                SetWeight(lines, a - 1, b - 1, c);
                SetWeight(weights, a - 1, b - 1, 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

            // この問題は、OK
            // なぜなら、連結グラフは、どの2頂点間にも、経路が存在するから。
            // つまり、あらかじめ、すべての点同士がつながっている。

            // 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);
                    //if (ab <= 0 || ab > 2)
                    if (ab > 2)
                    {
                        // aとbの中間点
                        for (int p = 0; p < n; p++)
                        {
                            var ap = GetWeight(weights, a, p);
                            var pb = GetWeight(weights, p, b);
                            // どちらかが経路確定済みでなければ、計算できない→経路未確定の時なんか、ない
                            //if (ap != 0 && pb != 0)
                            //{
                            // 最小値を記録
                            var weight = ap + pb;
                            //if (ab <= 0 || weight < ab)
                            if (weight < ab)
                            {
                                SetWeight(weights, a, b, weight);
                            }
                            //}
                        }
                    }
                }
            }

            // 三角形の2辺の重みより重い1辺があったら、それは最短距離でない
            var count = 0;
            for (int a = 0; a < n; a++)
            {
                for (int b = a + 1; b < n; b++)
                {
                    if (lines[a, b] > weights[a, b])
                    {
                        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)
        {
            var x = a;
            var y = b;
            if (a > b)
            {
                x = b;
                y = a;
            }
            return weights[x, y];
        }
    }
}