Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define pb(a) push_back(a)
#define INF 1145141919810
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5 + 5;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<ll> prime;

ll inv[dsize], fac[dsize];

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
inline ll GCD(ll a, ll b) {
  ll c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) {
  ll c = 1;
  while (b > 0) {
    if (b & 1) {
      c = a * c % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return c;
}
inline void _nCr() {
  fac[0] = 1;
  for (int i = 1; i < dsize; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 0; i < dsize; i++) {
    inv[i] = POW(fac[i], mod - 2);
  }
}
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; }
inline void PRI(ll n) {
  bool a[n + 1];
  for (int i = 0; i < n + 1; i++) {
    a[i] = 1;
  }
  for (int i = 2; i < n + 1; i++) {
    if (a[i]) {
      prime.pb(i);
      ll b = i;
      while (b <= n) {
        a[b] = 0;
        b += i;
      }
    }
  }
}

bool ans[dsize];

class WarshallFloyd {
public:
  vector<vector<ll>> d;

  void init(int n);
  void wf(int n);
};
void WarshallFloyd::init(int n) {
  d = vector<vector<ll>>(n, vector<ll>(n, INF));
  for (int i = 0; i < n; i++)
    d[i][i] = 0;
}
void WarshallFloyd::wf(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; i++) {
      for (int k = 0; k < n; i++) {
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
}
WarshallFloyd wf;
int main() {
  int n = in(), m = in();
  int ans;
  wf.init(n);
  vector<pair<pair<ll, ll>, ll>> edge;
  for (int i = 0; i < m; i++) {
    int x = in(), y = in(), z = in();
    edge.push_back({{x - 1, y - 1}, z});
    wf.d[x - 1][y - 1] = z;
    wf.d[y - 1][x - 1] = z;
  }
  wf.wf(n);
  for (int i = 0; i < m; i++) {
    int x = edge[i].first.first, y = edge[i].first.second;
    if (wf.d[x][y] < edge[i].second)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define pb(a) push_back(a)
#define INF 1145141919810
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5 + 5;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<ll> prime;

ll inv[dsize], fac[dsize];

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
inline ll GCD(ll a, ll b) {
  ll c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) {
  ll c = 1;
  while (b > 0) {
    if (b & 1) {
      c = a * c % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return c;
}
inline void _nCr() {
  fac[0] = 1;
  for (int i = 1; i < dsize; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 0; i < dsize; i++) {
    inv[i] = POW(fac[i], mod - 2);
  }
}
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; }
inline void PRI(ll n) {
  bool a[n + 1];
  for (int i = 0; i < n + 1; i++) {
    a[i] = 1;
  }
  for (int i = 2; i < n + 1; i++) {
    if (a[i]) {
      prime.pb(i);
      ll b = i;
      while (b <= n) {
        a[b] = 0;
        b += i;
      }
    }
  }
}

bool ans[dsize];

class WarshallFloyd {
public:
  vector<vector<ll>> d;

  void init(int n);
  void wf(int n);
};
void WarshallFloyd::init(int n) {
  d = vector<vector<ll>>(n, vector<ll>(n, INF));
  for (int i = 0; i < n; i++)
    d[i][i] = 0;
}
void WarshallFloyd::wf(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
}
WarshallFloyd wf;
int main() {
  int n = in(), m = in();
  int ans;
  wf.init(n);
  vector<pair<pair<ll, ll>, ll>> edge;
  for (int i = 0; i < m; i++) {
    int x = in(), y = in(), z = in();
    edge.push_back({{x - 1, y - 1}, z});
    wf.d[x - 1][y - 1] = z;
    wf.d[y - 1][x - 1] = z;
  }
  wf.wf(n);
  for (int i = 0; i < m; i++) {
    int x = edge[i].first.first, y = edge[i].first.second;
    if (wf.d[x][y] < edge[i].second)
      ans++;
  }
  cout << ans << endl;
}