-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarshallFloyd.cpp
More file actions
60 lines (54 loc) · 1003 Bytes
/
Copy pathWarshallFloyd.cpp
File metadata and controls
60 lines (54 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef long long ll;
using namespace std;
int main(){
int n,m,ta,tb;
std::cin >> n >> m;
int a[m],b[m],c[m];
int d[n+1][n+1];
fill(d[0],d[n+1],INF);
int ans=0,temp=1;
rep(i,m){
std::cin >> ta >> tb >> c[i];
a[i]=ta-1,b[i]=tb-1;
d[a[i]][b[i]]=c[i];
d[b[i]][a[i]]=c[i];
}
rep(i,n){
d[i][i]=0;
}
rep(k,n){
rep(i,n){
rep(j,n){
d[i][j]=min(d[i][j],d[i][k]+d[j][k]);
d[j][i]=d[i][j];
}
}
}
rep(k,m){
temp=1;
rep(i,n){
if(d[i][a[k]]+c[k]==d[i][b[k]]){
temp*=0;
break;
}
}
ans+=temp;
}
cout << ans << endl;
}