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.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static List<long[]>[] nextList = new List<long[]>[n];//頂点番号ごとの隣接リスト。距離、隣接頂点番号
static long[] colors = new long[n];//最短距離未確定の頂点が0、確定で2
static long[] distances = new long[n];//各頂点への最短距離
static long[] distanceMemos = new long[2];//キューから捨てた最短距離と頂点番号
static long answer = 0;

	static void Main()
	{

  
    for(long i = 0; i < n; i++) nextList[i] = new List<long[]>();//リストの宣言が必要
    for(long j = 0; j < m; j++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    
      long[] nextMemo = new long[2];
      nextMemo[1] = nums[1]-1;//隣接頂点番号
      nextMemo[0] = nums[2];//距離
      nextList[nums[0]-1].Add(nextMemo);//隣接リストの作成

      long[] nextMemoSub = new long[2];
      nextMemoSub[1] = nums[0]-1;//隣接頂点番号
      nextMemoSub[0] = nums[2];//距離
      nextList[nums[1]-1].Add(nextMemoSub);
    }
    
    for(int i = 0; i < n; i++) Dijkstra(i);

    answer /= 2;
    Console.WriteLine(answer);
	}

  static void Dijkstra(int startVertexNum)//O((|頂点数|+|辺数|)log頂点数)で各頂点への最短距離を求める
  {
    //Console.WriteLine(startVertexNum);
    List<long[]> distanceList = new List<long[]>();//優先度付きキュー
    for(long i = 0; i < n; i++)
    {
      distances[i] = long.MaxValue;//最短距離を無限とおく
      colors[i] = 0;
    }

    long[] newDistance = new long[2];

    //スタート地点を決める
    newDistance[1] = startVertexNum;//スタート地点番号
    distances[startVertexNum] = 0;
    colors[startVertexNum] = 1;

    newDistance[0] = 0;//スタートからスタートまでの距離0
    distanceList.Add(newDistance);
    distanceMemos[0] = 0;

    //Console.WriteLine(distanceList.Count());
    while(distanceList.Count() != 0)
    {
      distanceList = PopHeap(distanceList);
      long minVertex = distanceMemos[1];//最短頂点の番号
      colors[minVertex] = 2;
      //Console.WriteLine(distances[minVertex] +"&"+ distanceMemos[0]);
      if(distances[minVertex] < distanceMemos[0]) continue;//最小値が最短でないなら無視
      //Console.WriteLine(nextList[minVertex].Count()+"a");
      for(long i = 0; i < nextList[minVertex].Count(); i++)
      {
        long v = nextList[minVertex][(int)i][1];
        if(colors[v] == 2) continue;
        if(distances[v] > distances[minVertex] + nextList[minVertex][(int)i][0])
        {
          distances[v] = distances[minVertex] + nextList[minVertex][(int)i][0];
          long[] newDistanceSub = new long[2];
          newDistanceSub[0] = distances[v];
          newDistanceSub[1] = v;
          distanceList = PushHeap(distanceList, newDistanceSub);
          colors[v] = 1;
        }
      }
    }

    for(int i = 0; i < nextList[startVertexNum].Count(); i++)
    {
      if(distances[nextList[startVertexNum][i][1]] < nextList[startVertexNum][i][0]) answer++;
      //Console.WriteLine(distances[nextList[startVertexNum][i][1]] +" "+ nextList[startVertexNum][i][0]);
    }
    
  }

  //引数は、昇順にソート済みのリスト
  static List<long[]> PushHeap(List<long[]> nums, long[] addNums)//現在のヒープnumsにaddNumを追加
  {
    int n = nums.Count;
    nums.Add(addNums);

    while (n > 0)
    {
      int i = (n-1)/2;
      if (nums[n][0] < nums[i][0])//親のほうが大きいなら入れ替え。
      {
        long tmp = nums[n][0];
        long tmpSub = nums[n][1];
        nums[n][0] = nums[i][0];
        nums[n][1] = nums[i][1];
        nums[i][0] = tmp;
        nums[i][1] = tmpSub;
      }
      n = i;
    }
    return nums;
  }

  static List<long[]> PopHeap(List<long[]> nums)//ヒープnumsからポップ
  {
    int n = nums.Count - 1;
    distanceMemos[0] = nums[0][0];//捨てる値の保存
    distanceMemos[1] = nums[0][1];
    nums[0][0] = nums[n][0];//最小値である根を削除してリストの最後を持ってくる
    nums[0][1] = nums[n][1];
    nums.RemoveAt(n);

    for (int i = 0, j; (j = 2*i+1) < n;)
    {
      if ((j != n-1) && (nums[j][0] > nums[j+1][0]))// ２つの子のうち、値の小さい方を選ぶ
        j++;
      if (nums[i][0] > nums[j][0])//子が親より小さいなら入れ替え
      {
        long tmp = nums[j][0];
        long tmpSub = nums[j][1];
        nums[j][0] = nums[i][0];
        nums[j][1] = nums[i][1];
        nums[i][0] = tmp;
        nums[i][1] = tmpSub;
      }
      i = j;
    }
    return nums;
  }
  
}