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)

//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, E, C;
	List<E> all;
	List<E>[] es;
	void Solve()
	{
		var I = G();
		V = I[0];
		E = I[1];
		all = new List<E>();
		es = new List<E>[V];
		for (var i = 0; i < V; i++) es[i] = new List<E>();
		for (var i = 0; i < E; i++)
		{
			I = G();
			AddEdge(I[0] - 1, I[1] - 1, I[2]);
		}
		var d = new int[V, V];
		for (var i = 0; i < V; i++)
		{
			var e = DijkstraFrom(i);
			for (var j = 0; j < V; j++) d[i, j] = e[j];
		}
		var c = E;
		foreach (var e in all)
		{
			var flag = false;
			for (var i = 0; i < V; i++)
				if (d[i, e.From] + e.Cost == d[i, e.To])
				{
					flag = true;
					break;
				}
			if (flag) c--;
		}
		WriteLine(c);
	}
	void AddEdge(int f, int t, int c)
	{
		var e = new E(f, t, c);
		es[f].Add(e);
		es[t].Add(new E(t, f, c));
		all.Add(e);
		C = Max(C, c);
	}
	int[] DijkstraFrom(int from)
	{
		var d = Enumerable.Repeat(MOD, V).ToArray();
		var queue = new DialQueue(C);
		d[from] = 0;
		queue.Add(from, 0);
		while (queue.Any)
		{
			var p = queue.Pop();
			var v = p.To;
			if (d[v] < p.Cost) continue;
			foreach (var e in es[v])
			{
				var tmp = d[v] + e.Cost;
				if (d[e.To] > tmp)
				{
					if (d[e.To] != MOD) queue.Move(e.To, d[e.To], tmp);
					else queue.Add(e.To, tmp);
					d[e.To] = tmp;
				}
			}
		}
		return d;
	}
}
struct E
{
	public int From, To, Cost;
	public E(int f, int t, int c)
	{
		From = f;
		To = t;
		Cost = c;
	}
	public override string ToString()
	{
		return string.Format("From = {0}, To = {1}, Cost = {2}", From, To, Cost);
	}
}
class DialQueue
{
	public int Count { get; private set; }
	int C, offset;
	HashSet<int>[] buckets;
	HashSet<int> this[int n] { get { return buckets[(n - offset + offset % C) % C]; } }
	public DialQueue(int c)
	{
		C = c + 1;
		buckets = new HashSet<int>[C];
		for (var i = 0; i < C; i++) buckets[i] = new HashSet<int>();
	}
	public void Add(int v, int d)
	{
		Count++;
		this[d].Add(v);
	}
	public void Move(int v, int prev, int now)
	{
		this[prev].Remove(v);
		this[now].Add(v);
	}
	public bool Any { get { return Count > 0; } }
	public E Pop()
	{
		Count--;
		var t = offset;
		while (true)
		{
			var s = this[t];
			if (s.Count > 0)
			{
				var v = s.First();
				s.Remove(v);
				offset = t;
				return new E(-1, v, t);
			}
			t++;
		}
	}
	public override string ToString()
	{
		return string.Format("C = {0}, Offset = {1}, count = {2}", C, offset, Count);
	}
}