Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream &operator<<(ostream &out, const set<T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define int long long
using P = pair<int, int>;
// #########################################
int dist[1100][1100];
const int INF = 1001001001;
signed main() {
  int n, m;
  cin >> n >> m;
  rep(i, 110) rep(j, 110) dist[i][j] = INF;
  int a[n], b[n], c[n];
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  rep(i, n) rep(j, n) rep(k, n) dist[j][k] =
      min(dist[j][k], dist[j][i] + dist[i][k]);

  int ret = 0;
  // rep(i,n)rep(j,n)trace(i,j,dist[i][j]);
  rep(edge, m) {
    bool found = false;
    rep(i, n) rep(j, n) {
      // i - j kの辺
      int u = a[edge], v = b[edge], d = c[edge];
      if (dist[i][u] + d + dist[v][j] == dist[i][j]) {
        found = true;
        break;
      }
    }
    ret += !found;
  }
  cout << ret << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) {
  out << "[";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream &operator<<(ostream &out, const set<T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) {
  out << "{";
  bool first = true;
  for (auto &p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define int long long
using P = pair<int, int>;
// #########################################
int dist[1100][1100];
const int INF = 1001001001;
signed main() {
  int n, m;
  cin >> n >> m;
  rep(i, 110) rep(j, 110) dist[i][j] = INF;
  int a[m], b[m], c[m];
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  rep(i, n) rep(j, n) rep(k, n) dist[j][k] =
      min(dist[j][k], dist[j][i] + dist[i][k]);

  int ret = 0;
  // rep(i,n)rep(j,n)trace(i,j,dist[i][j]);
  rep(edge, m) {
    bool found = false;
    rep(i, n) rep(j, n) {
      // i - j kの辺
      int u = a[edge], v = b[edge], d = c[edge];
      if (dist[i][u] + d + dist[v][j] == dist[i][j]) {
        found = true;
        break;
      }
    }
    ret += !found;
  }
  cout << ret << endl;

  return 0;
}