Problem p03837 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned ui;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, int> d_i;
typedef pair<double, double> d_d;

#ifdef DEBUG
#define dprintf printf
#define dputs puts
#define dout(x) cout << #x " = " << (x) << endl
#define darray(x, n)                                                           \
  {                                                                            \
    int i;                                                                     \
    rep(i, n) cout << #x "[" << i << "] = " << *((x) + i) << endl;             \
  }
#define dloop(i, s, g) for (int(i) = (s); (i) < (g); (i)++)
#define drep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define dstop() scanf("%*c")
#else
#define dprintf (1) ? 0 : printf
#define dputs (1) ? 0 : puts
#define dout(x)
#define darray(x, n)
#define dloop(i, s, g)                                                         \
  if (int i = 0) {                                                             \
  } else
#define drep(i, n)                                                             \
  if (int i = 0) {                                                             \
  } else
#define dstop()
#endif

#define F first
#define S second
#define pb push_back
#define mp make_pair

#define loop(i, s, g) for ((i) = (s); (i) < (g); (i)++)
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define all(x) (x.begin(), x.end())
#define in(T, ...)                                                             \
  T __VA_ARGS__;                                                               \
  impl(__VA_ARGS__)
#define array(T, id, n)                                                        \
  T id[(n)];                                                                   \
  for (int i = 0; i < (n); i++)                                                \
  cin >> id[i]
#define putv(n) cout << (n) << endl

// #define int long long
#ifndef int
#define INF 1001001001
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T, typename... TS> void impl(T &head, TS &...tail) {
  cin >> head;
  impl(tail...);
}

#define MAX_V 200
int d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
  int i, j, k;
  rep(k, V) rep(i, V) rep(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

struct Edge {
  int s;
  int t;
  int c;
};

signed main(void) {
  int i, j, k;
  rep(i, MAX_V) rep(j, MAX_V) d[i][j] = i == j ? 0 : INF;
  Edge e[MAX_V] = {};

  cin >> V;
  in(int, M);
  rep(i, M) {
    in(int, a, b, c);
    if (a > b)
      swap(a, b);
    e[i] = (Edge){a - 1, b - 1, c};
    d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }

  warshall_floyd();

  drep(i, V) {
    drep(j, V) dprintf("%4d,", d[i][j]);
    puts("");
  }

  int count = M;
  rep(k, M) {
    bool flg = false;
    for (i = 0; i < V; i++) {
      for (j = 0; j < V; j++) {
        if (d[i][e[k].s] + e[k].c + d[e[k].t][j] == d[i][j])
          flg = true;
      }
    }
    count -= flg;
  }
  putv(count);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned ui;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, int> d_i;
typedef pair<double, double> d_d;

#ifdef DEBUG
#define dprintf printf
#define dputs puts
#define dout(x) cout << #x " = " << (x) << endl
#define darray(x, n)                                                           \
  {                                                                            \
    int i;                                                                     \
    rep(i, n) cout << #x "[" << i << "] = " << *((x) + i) << endl;             \
  }
#define dloop(i, s, g) for (int(i) = (s); (i) < (g); (i)++)
#define drep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define dstop() scanf("%*c")
#else
#define dprintf (1) ? 0 : printf
#define dputs (1) ? 0 : puts
#define dout(x)
#define darray(x, n)
#define dloop(i, s, g)                                                         \
  if (int i = 0) {                                                             \
  } else
#define drep(i, n)                                                             \
  if (int i = 0) {                                                             \
  } else
#define dstop()
#endif

#define F first
#define S second
#define pb push_back
#define mp make_pair

#define loop(i, s, g) for ((i) = (s); (i) < (g); (i)++)
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define all(x) (x.begin(), x.end())
#define in(T, ...)                                                             \
  T __VA_ARGS__;                                                               \
  impl(__VA_ARGS__)
#define array(T, id, n)                                                        \
  T id[(n)];                                                                   \
  for (int i = 0; i < (n); i++)                                                \
  cin >> id[i]
#define putv(n) cout << (n) << endl

// #define int long long
#ifndef int
#define INF 1001001001
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T, typename... TS> void impl(T &head, TS &...tail) {
  cin >> head;
  impl(tail...);
}

#define MAX_V 200
int d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
  int i, j, k;
  rep(k, V) rep(i, V) rep(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

struct Edge {
  int s;
  int t;
  int c;
};

signed main(void) {
  int i, j, k;
  rep(i, MAX_V) rep(j, MAX_V) d[i][j] = i == j ? 0 : INF;
  Edge e[2000] = {};

  cin >> V;
  in(int, M);
  rep(i, M) {
    in(int, a, b, c);
    if (a > b)
      swap(a, b);
    e[i] = (Edge){a - 1, b - 1, c};
    d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }

  warshall_floyd();

  drep(i, V) {
    drep(j, V) dprintf("%4d,", d[i][j]);
    puts("");
  }

  int count = M;
  rep(k, M) {
    bool flg = false;
    for (i = 0; i < V; i++) {
      for (j = 0; j < V; j++) {
        if (d[i][e[k].s] + e[k].c + d[e[k].t][j] == d[i][j])
          flg = true;
      }
    }
    count -= flg;
  }
  putv(count);
  return 0;
}