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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    partial class Program
    {
        static long mod = 1000000007;
        static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
            Console.ReadKey();
        }

        //ここから
        static void Solve()
        {
            int N; int M;
            Multi(out N, out M);
            var abc = GetIntJaggedArray(M);
            var path = Enumerable.Range(0, N).ToDictionary(s => s, s => new List<Tuple<int, int>>());
            for (int i = 0; i < M; i++)
            {
                var a = abc[i][0] - 1;
                var b = abc[i][1] - 1;
                var c = abc[i][2];
                path[a].Add(new Tuple<int, int>(b, c));
                path[b].Add(new Tuple<int, int>(a, c));
            }

            var set = new HashSet<Tuple<int, int>>();

            var haschecked = CreateJaggedArray(N, N, false);
            for (int i = 0; i < N; i++)
            {
                haschecked[i][i] = true;
            }

            PriorityQueue<Pair> pq;
            int[] len; ;
            int[] from;
            for (int s = 0; s < N; s++)
            {
                for (int g = 0; g < N; g++)
                {
                    if (haschecked[s][g]) continue;

                    pq = new PriorityQueue<Pair>();
                    len = Enumerable.Repeat(-1, N).ToArray();
                    from = Enumerable.Repeat(-1, N).ToArray();

                    pq.Push(new Pair(s, 0));
                    len[s] = 0;
                    while (pq.Count > 0)
                    {
                        var now = pq.Peek();
                        pq.Pop();
                        foreach (var next in path[now.Node])
                        {
                            var cost = now.Cost + next.Item2;
                            if (len[next.Item1] == -1 || len[next.Item1] > cost)
                            {
                                len[next.Item1] = cost;
                                from[next.Item1] = now.Node;
                                pq.Push(new Pair(next.Item1, cost));
                            }
                        }
                    }
                    var tmp = new HashSet<int>();
                    while (from[g] != -1)
                    {
                        tmp.Add(g);
                        set.Add(new Tuple<int, int>(Math.Min(g, from[g]), Math.Max(g, from[g])));
                        g = from[g];
                    }
                    tmp.Add(s);

                    var hoge = tmp.ToArray();
                    for(int i = 0; i < tmp.Count; i++)
                    {
                        for(int j = 0; j < tmp.Count; j++)
                        {
                            haschecked[hoge[i]][hoge[j]] = true;
                        }
                    }

                }
            }

            var ans = M - set.Count;
            Console.WriteLine(ans);

        }
    }

    class Pair : IComparable<Pair>
    {
        public Pair(int node, int cost)
        {
            Node = node; Cost = cost;
        }
        public int Node { get; set; }
        public int Cost { get; set; }
        public int CompareTo(Pair p)
        {
            return p.Cost > Cost ? 1 : -1;
        }
    }

    class PriorityQueue<T> where T : IComparable<T>
    {
        public PriorityQueue()
        {
            buffer = new List<T>();
        }

        List<T> buffer;
        public void Push(T elem)
        {
            int n = buffer.Count;
            buffer.Add(elem);
            while (n != 0)
            {
                int i = (n - 1) / 2;
                if (buffer[n].CompareTo(buffer[i]) > 0)
                {
                    T temp = buffer[n];
                    buffer[n] = buffer[i];
                    buffer[i] = temp;
                }
                n = i;
            }
        }

        public void Pop()
        {
            int n = buffer.Count - 1;
            buffer[0] = buffer[n];
            buffer.RemoveAt(n);
            for (int i = 0, j; (j = 2 * i + 1) < n;)
            {
                if ((j != n - 1) && (buffer[j].CompareTo(buffer[j + 1]) < 0)) { j++; }
                if (buffer[i].CompareTo(buffer[j]) < 0)
                {
                    T temp = buffer[j];
                    buffer[j] = buffer[i];
                    buffer[i] = temp;
                }
                i = j;
            }
        }

        public T Peek()
        {
            return buffer[0];
        }

        public int Count { get { return buffer.Count; } }
    }

    public static class Ex
    {
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
    }

    partial class Program
    {
        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
        static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
        static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
        static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); }
        static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); }
        static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H).Select(s => Enumerable.Repeat(value, W).ToArray()).ToArray(); }
        static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetIntArray().ToArray()).ToArray(); }
        static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetLongArray().ToArray()).ToArray(); }
        static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetStr().ToCharArray()).ToArray(); }
        static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); }


        static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
        }
        static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]);
        }
    }
}