Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll, ll>>;

typedef unsigned long long ull;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) {
  T a = 1;
  while (p) {
    if (p % 2)
      a = a * x % m;
    x = x + x % m;
    p /= 2;
  }
  return a;
}
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout <<
// a[i]; } cout << "\n"; }

#define mod 1000000007LL
#define INF 10000000000000000LL

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)

#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
// #define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2;
// } return a; }

#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(), (n).end()
#define bit(n) (1LL << (n))
#define pb push_back

// #ifdef LOCAL
//
// #define dpri(...) fprintf(stderr, __VA_ARGS__)
// #define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout <<
// g[i][j] << " "; cout << "}" << "\n"; } #else #define dpri(...) 42 #define
// pria(g) 42 #endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n, m;
  cin >> n >> m;
  ll a[n], b[n], c[n];
  ll disp[n][n];

  rep(i, n) rep(j, n) if (i == j) disp[i][j] = 0;
  else disp[i][j] = INF;

  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    disp[a[i] - 1][b[i] - 1] = c[i];
    disp[b[i] - 1][a[i] - 1] = c[i];
  }

  rep(k, n) rep(i, n) rep(j, n) disp[i][j] =
      min(disp[i][j], disp[i][k] + disp[k][j]);

  ll ans = m;
  rep(i, m) {
    if (disp[a[i] - 1][b[i] - 1] == c[i])
      ans--;
  }
  pri(ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll, ll>>;

typedef unsigned long long ull;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) {
  T a = 1;
  while (p) {
    if (p % 2)
      a = a * x % m;
    x = x + x % m;
    p /= 2;
  }
  return a;
}
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout <<
// a[i]; } cout << "\n"; }

#define mod 1000000007LL
#define INF 10000000000000000LL

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)

#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
// #define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2;
// } return a; }

#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(), (n).end()
#define bit(n) (1LL << (n))
#define pb push_back

// #ifdef LOCAL
//
// #define dpri(...) fprintf(stderr, __VA_ARGS__)
// #define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout <<
// g[i][j] << " "; cout << "}" << "\n"; } #else #define dpri(...) 42 #define
// pria(g) 42 #endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n, m;
  cin >> n >> m;
  ll a[m], b[m], c[m];
  ll disp[n][n];

  rep(i, n) rep(j, n) if (i == j) disp[i][j] = 0;
  else disp[i][j] = INF;

  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    disp[a[i] - 1][b[i] - 1] = c[i];
    disp[b[i] - 1][a[i] - 1] = c[i];
  }

  rep(k, n) rep(i, n) rep(j, n) disp[i][j] =
      min(disp[i][j], disp[i][k] + disp[k][j]);

  ll ans = m;
  rep(i, m) {
    if (disp[a[i] - 1][b[i] - 1] == c[i])
      ans--;
  }
  pri(ans);

  return 0;
}