Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i, init, a) for (int i = init; i < a; i++)
#define rep(i, a) FOR(i, 0, a)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define rep1(i, a) for (int i = 1; i <= a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a, b) cout << a << " " << b << endl;
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl;
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a, n) memset(a, n, sizeof(a))
#define all(a) a.begin(), a.end()
#define chmin(a, b) a = min(a, b);
#define chmax(a, b) a = max(a, b);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int A[109], B[109], C[109];
int G[109][109];

void warshallFloyd(int n) {

  rep(k, n) {
    rep(i, n) {
      if (G[i][k] == INF)
        continue;
      rep(j, n) {
        if (G[k][j] == INF)
          continue;
        if (G[i][j] > G[i][k] + G[k][j])
          G[i][j] = G[i][k] + G[k][j];
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  rep(i, 109) rep(j, 109) G[i][j] = INF;
  rep(i, 109) G[i][i] = 0;

  int N, M;
  cin >> N >> M;

  rep(i, M) cin >> A[i] >> B[i] >> C[i];
  rep(i, M) {
    G[--A[i]][--B[i]] = C[i];
    G[B[i]][A[i]] = C[i];
  }

  warshallFloyd(N);

  int cnt = 0;
  rep(i, M) {
    if (G[A[i]][B[i]] < C[i])
      cnt++;
  }

  cout1(cnt)
}

Fixed submission:
#include "bits/stdc++.h"
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i, init, a) for (int i = init; i < a; i++)
#define rep(i, a) FOR(i, 0, a)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define rep1(i, a) for (int i = 1; i <= a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a, b) cout << a << " " << b << endl;
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl;
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a, n) memset(a, n, sizeof(a))
#define all(a) a.begin(), a.end()
#define chmin(a, b) a = min(a, b);
#define chmax(a, b) a = max(a, b);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int A[1009], B[1009], C[1009];
int G[109][109];

void warshallFloyd(int n) {

  rep(k, n) {
    rep(i, n) {
      if (G[i][k] == INF)
        continue;
      rep(j, n) {
        if (G[k][j] == INF)
          continue;
        if (G[i][j] > G[i][k] + G[k][j])
          G[i][j] = G[i][k] + G[k][j];
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  rep(i, 109) rep(j, 109) G[i][j] = INF;
  rep(i, 109) G[i][i] = 0;

  int N, M;
  cin >> N >> M;

  rep(i, M) cin >> A[i] >> B[i] >> C[i];
  rep(i, M) {
    G[--A[i]][--B[i]] = C[i];
    G[B[i]][A[i]] = C[i];
  }

  warshallFloyd(N);

  int cnt = 0;
  rep(i, M) {
    if (G[A[i]][B[i]] < C[i])
      cnt++;
  }

  cout1(cnt)
}