Skip to content

Instantly share code, notes, and snippets.

@takageymt
Created February 16, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takageymt/9dcb70ca06d3c7f08ca38666e1e42f3b to your computer and use it in GitHub Desktop.
Save takageymt/9dcb70ca06d3c7f08ca38666e1e42f3b to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
const int inf = 1LL << 55;
const int mod = 1e9 + 7;
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int n, m;
cin >> n >> m;
int g[101][101], h[101][101];
fill(g[0], g[101], inf);
fill(h[0], h[101], inf);
rep(i, 101) g[i][i] = h[i][i] = 0;
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
g[a][b] = g[b][a] = h[a][b] = h[b][a] = c;
}
rep(i, n) rep(j, n) rep(k, n) {
g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
}
int ans = 0;
rep(i, n) reps(j, i+1, n) {
if(h[i][j] == inf) continue;
if(g[i][j] != h[i][j]) ans++;
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment