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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
//#include<string>
//#include<sstream>
using namespace std; 
const int MAX_V=10000+5;
const int INF=1<<30;
int pre[MAX_V];
int cost[MAX_V][MAX_V];//cost[u][v]表示边e=(u,v)的权值（不存在这条边时设为INF）
bool visited[MAX_V][MAX_V];
int d[MAX_V];//顶点s出发的最短距离
bool used[MAX_V];//已经使用过的图
int V,E;//顶点数，边数
//求从起点s出发到各个顶点的最短距离
void dijkstra(int s)
{
    fill(d+1,d+V+1,INF);
    fill(used+1,used+V+1,false);
    fill(pre+1,pre+V+1,-1);
    d[s]=0;
    while(true)
    {
        int v=-1;
        //从尚未使用过的顶点中选择一个距离最小的顶点
        for(int u=1; u<=V; u++)
        {
            if(!used[u]&&(v==-1||d[u]<d[v]))
                v=u;
        }
        if(v==-1)
            break;
        used[v]=true;
        for(int u=1; u<=V; u++)
        {
            if(d[u]>d[v]+cost[v][u])
            {
                d[u]=d[v]+cost[v][u];
                pre[u]=v;
            }
        }
    }
}
vector<int> get_path(int t)
{
    vector<int>path;
    for(; t!=-1; t=pre[t])
        path.push_back(t);
    reverse(path.begin(),path.end());
    return path;
}
int main()
{
    scanf("%d%d",&V,&E);
    int a,b,c;
    for(int i=1;i<=V;i++)
    {
        for(int j=1;j<=V;j++)
            cost[i][j]=INF;
    }
    for(int i=0;i<E;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        cost[a][b]=cost[b][a]=c;
    }
    memset(visited,false,sizeof(visited));
    int ans=E;
    for(int i=1;i<=V;i++)
    {
        dijkstra(i);
        for(int j=1;j<=V;j++)
        {
            if(i==j)
                continue;
            vector<int>v=get_path(j);
            for(int i=0;i<v.size()-1;i++)
            {
                int a=v[i];
                int b=v[i+1];
                if(!visited[v[i]][v[i+1]]&&!visited[v[i+1]][v[i]])
                {
                    visited[v[i]][v[i+1]]=visited[v[i+1]][v[i]]=true;
                    ans--;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}