prithivMLmods/Coder-Stat huggingface dataset:
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n);
  vector<vector<int>> dist(n, vector<int>(n, 1e7));
  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]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }
  rep(k, n) rep(i, n) rep(j, n) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }
  int ans = m;
  rep(i, m) {
    bool isCandidate = false;
    rep(s, n) rep(t, n) {
      if (s == t)
        continue;
      if (dist[s][t] == dist[s][a[i]] + c[i] + dist[b[i]][t]) {
        isCandidate = true;
      }
    }
    if (isCandidate)
      ans--;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m), c(m);
  vector<vector<int>> dist(n, vector<int>(n, 1e7));
  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]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }
  rep(k, n) rep(i, n) rep(j, n) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }
  int ans = m;
  rep(i, m) {
    bool isCandidate = false;
    rep(s, n) rep(t, n) {
      if (s == t)
        continue;
      if (dist[s][t] == dist[s][a[i]] + c[i] + dist[b[i]][t]) {
        isCandidate = true;
      }
    }
    if (isCandidate)
      ans--;
  }
  cout << ans << endl;
}
Problem p03837 (C++)

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

typedef long long ll;

static const int MAX = 110;
static const int INFTY = (1 << 30);

int n, m;
int d[MAX][MAX];
int a[MAX], b[MAX], c[MAX];

// ワーシャルフロイド（全点対間最短経路）
void floyd() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (d[i][k] == INFTY)
        continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY)
          continue;
        // 頂点 k を経由する場合としない場合の最小コストを求める
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = ((i == j) ? 0 : INFTY);
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < m; i++) {
    d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
    d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
  }

  floyd();

  int ans = m;
  for (int i = 0; i < m; i++) {
    bool include = false;
    for (int j = 0; j < n; j++) {
      if (d[j][a[i]] + c[i] == d[j][b[i]])
        include = true;
    }
    if (include)
      ans--;
  }

  cout << ans << endl;
}


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

typedef long long ll;

static const int MAX = 1100;
static const int INFTY = (1 << 30);

int n, m;
int d[MAX][MAX];
int a[MAX], b[MAX], c[MAX];

// ワーシャルフロイド（全点対間最短経路）
void floyd() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (d[i][k] == INFTY)
        continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY)
          continue;
        // 頂点 k を経由する場合としない場合の最小コストを求める
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = ((i == j) ? 0 : INFTY);
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < m; i++) {
    d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
    d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
  }

  floyd();

  int ans = m;
  for (int i = 0; i < m; i++) {
    bool include = false;
    for (int j = 0; j < n; j++) {
      if (d[j][a[i]] + c[i] == d[j][b[i]])
        include = true;
    }
    if (include)
      ans--;
  }

  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(), (a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector<int>;
using vvi = vector<vi>;

signed main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> g[n][n];
  rep(i, n) rep(j, n) g[i][j] =
      i == j ? make_pair(0LL, 0LL) : make_pair(INF, INF);

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a][b] = g[b][a] = make_pair(c, c);
  }

  rep(k, m) rep(i, m) rep(j, m) g[i][j].first =
      min(g[i][j].first, g[i][k].first + g[k][j].first);

  int ans = 0;
  rep(i, n) range(j, i + 1, n) {
    bool belong = false;
    if (g[i][j].second == INF)
      continue;
    rep(k, n) {
      if (i == k)
        continue;
      if (g[i][k].first == g[i][j].second + g[j][k].first)
        belong = true;
    }
    ans += !belong;
  }

  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for (auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(), (a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector<int>;
using vvi = vector<vi>;

signed main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> g[n][n];
  rep(i, n) rep(j, n) g[i][j] =
      i == j ? make_pair(0LL, 0LL) : make_pair(INF, INF);

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a][b] = g[b][a] = make_pair(c, c);
  }

  rep(k, n) rep(i, n) rep(j, n) g[i][j].first =
      min(g[i][j].first, g[i][k].first + g[k][j].first);

  int ans = 0;
  rep(i, n) range(j, i + 1, n) {
    bool belong = false;
    if (g[i][j].second == INF)
      continue;
    rep(k, n) {
      if (i == k)
        continue;
      if (g[i][k].first == g[i][j].second + g[j][k].first)
        belong = true;
    }
    ans += !belong;
  }

  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
#include <vector>
using namespace std;
const int inf = 1e8;
typedef pair<int, int> pii;

int main() {

  int N, M;
  cin >> N >> M;
  int a[M], b[M], c[M];
  for (int i = 0; i < M; i++)
    cin >> a[i] >> b[i] >> c[i];

  int g[N][N];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (i != j)
        g[i][j] = inf;

  for (int i = 0; i < M; i++) {
    g[a[i] - 1][b[i] - 1] = c[i];
    g[b[i] - 1][a[i] - 1] = c[i];
  }

  int next[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      next[i][j] = j;
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (g[i][j] > g[i][k] + g[k][j]) {
          g[i][j] = g[i][k] + g[k][j];
          next[i][j] = next[i][k];
        }
      }
    }
  }

  int used[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      used[i][j] = 0;
    }
  }
  for (int start = 0; start < N; start++) {
    for (int goal = start + 1; goal < N; goal++) {
      for (int i = start; i != goal; i = next[i][goal]) {
        used[i][next[i][goal]] = 1;
        used[next[i][goal]][i] = 1;
      }
    }
  }

  int s = 0;
  for (int i = 0; i < M; i++) {
    if (used[a[i] - 1][b[i] - 1])
      s++;
  }

  cout << M - s << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <set>
#include <vector>
using namespace std;
const int inf = 1e8;
typedef pair<int, int> pii;

int main() {

  int N, M;
  cin >> N >> M;
  int a[M], b[M], c[M];
  for (int i = 0; i < M; i++)
    cin >> a[i] >> b[i] >> c[i];

  int g[N][N];
  for (int i = 0; i < N; i++)
    g[i][i] = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (i != j)
        g[i][j] = inf;

  for (int i = 0; i < M; i++) {
    g[a[i] - 1][b[i] - 1] = c[i];
    g[b[i] - 1][a[i] - 1] = c[i];
  }

  int next[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      next[i][j] = j;
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (g[i][j] > g[i][k] + g[k][j]) {
          g[i][j] = g[i][k] + g[k][j];
          next[i][j] = next[i][k];
        }
      }
    }
  }

  int used[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      used[i][j] = 0;
    }
  }
  for (int start = 0; start < N; start++) {
    for (int goal = start + 1; goal < N; goal++) {
      for (int i = start; i != goal; i = next[i][goal]) {
        used[i][next[i][goal]] = 1;
        used[next[i][goal]][i] = 1;
      }
    }
  }

  int s = 0;
  for (int i = 0; i < M; i++) {
    if (used[a[i] - 1][b[i] - 1])
      s++;
  }

  cout << M - s << endl;

  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int n, m, a[105], b[105], c[105];
int g[105][105];

int main() {
  int n, m;
  cin >> n >> m;

  rep(i, n) rep(j, n) g[i][j] = INF;
  rep(i, n) g[i][i] = 0;
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { chmin(g[i][j], g[i][k] + g[k][j]); }
    }
  }

  int ans = 0;
  rep(i, m) {
    if (c[i] > g[a[i]][b[i]])
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int n, m, a[1005], b[1005], c[1005];
int g[105][105];

int main() {
  int n, m;
  cin >> n >> m;

  rep(i, n) rep(j, n) g[i][j] = INF;
  rep(i, n) g[i][i] = 0;
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { chmin(g[i][j], g[i][k] + g[k][j]); }
    }
  }

  int ans = 0;
  rep(i, m) {
    if (c[i] > g[a[i]][b[i]])
      ans++;
  }
  cout << ans << endl;
}
Problem p03837 (C++)

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

const int N = 105;
const int inf = 1e8;
int c[N][N], edge[N][N];
int dist[N];
vector<int> conn[N];
bool inpath[N];
int n;

void dijkstra(int u) {
  fill_n(dist, N, inf);
  vector<bool> processed(N, false);
  vector<int> parent(N, -1);

  dist[u] = 0;
  priority_queue<pair<int, int>> pq;
  pq.emplace(0, u);

  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    if (processed[u])
      continue;
    processed[u] = true;
    for (int v : conn[u]) {
      if (dist[v] > dist[u] + c[u][v]) {
        dist[v] = dist[u] + c[u][v];
        parent[v] = u;
        pq.emplace(-dist[v], v);
      }
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (i == u)
      continue;
    int x = i;
    while (1) {
      int p = parent[x];
      if (p == -1)
        break;
      inpath[edge[p][x]] = true;
      x = p;
    }
  }
}

int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    c[u][v] = c[v][u] = w;
    edge[u][v] = edge[v][u] = i;
    conn[u].emplace_back(v);
    conn[v].emplace_back(u);
  }

  for (int i = 1; i <= n; ++i) {
    dijkstra(i);
  }

  int res = 0;
  for (int i = 1; i <= m; ++i)
    if (!inpath[i])
      res++;
  cout << res << endl;
}

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

const int N = 105;
const int inf = 1e8;
int c[N][N], edge[N][N];
int dist[N];
vector<int> conn[N];
bool inpath[1005];
int n;

void dijkstra(int u) {
  fill_n(dist, N, inf);
  vector<bool> processed(N, false);
  vector<int> parent(N, -1);

  dist[u] = 0;
  priority_queue<pair<int, int>> pq;
  pq.emplace(0, u);

  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    if (processed[u])
      continue;
    processed[u] = true;
    for (int v : conn[u]) {
      if (dist[v] > dist[u] + c[u][v]) {
        dist[v] = dist[u] + c[u][v];
        parent[v] = u;
        pq.emplace(-dist[v], v);
      }
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (i == u)
      continue;
    int x = i;
    while (1) {
      int p = parent[x];
      if (p == -1)
        break;
      inpath[edge[p][x]] = true;
      x = p;
    }
  }
}

int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    c[u][v] = c[v][u] = w;
    edge[u][v] = edge[v][u] = i;
    conn[u].emplace_back(v);
    conn[v].emplace_back(u);
  }

  for (int i = 1; i <= n; ++i) {
    dijkstra(i);
  }

  int res = 0;
  for (int i = 1; i <= m; ++i)
    if (!inpath[i])
      res++;
  cout << res << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T> std::string tostr(const T &t) {
  std::ostringstream os;
  os << t;
  return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> cost(n);
  vector<P> pa(m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    pa[i] = {a, b};
    cost[i] = c;
  }
  // ワーシャルフロイド
  vector<vector<ll>> dist(n, vector<ll>(n, INF));
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    dist[pa[i].first][pa[i].second] = cost[i];
    dist[pa[i].second][pa[i].first] = cost[i];
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  ans = m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[j][pa[i].first] + cost[i] == dist[j][pa[i].second]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T> std::string tostr(const T &t) {
  std::ostringstream os;
  os << t;
  return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> cost(m);
  vector<P> pa(m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    pa[i] = {a, b};
    cost[i] = c;
  }
  // ワーシャルフロイド
  vector<vector<ll>> dist(n, vector<ll>(n, INF));
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    dist[pa[i].first][pa[i].second] = cost[i];
    dist[pa[i].second][pa[i].first] = cost[i];
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  ans = m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[j][pa[i].first] + cost[i] == dist[j][pa[i].second]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 105, inf = 1e17;
ll a[N], b[N], c[N], dist[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m, ans = 0;
  cin >> n >> m;
  for (ll i = 0; i < m; i++)
    cin >> a[i] >> b[i] >> c[i], a[i] -= 1, b[i] -= 1;
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < n; j++)
      dist[i][j] = (i == j ? 0 : inf);
  for (ll i = 0; i < m; i++)
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
  for (ll i = 0; i < m; i++)
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  for (ll k = 0; k < n; k++)
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  for (ll i = 0, chk = 0; i < m; i++, chk = 0) {
    for (ll j = 0; j < n; j++)
      if (dist[j][a[i]] + c[i] == dist[j][b[i]])
        chk = 1;
    ans += chk;
  }
  cout << m - ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1005, inf = 1e17;
ll a[N], b[N], c[N], dist[105][105];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m, ans = 0;
  cin >> n >> m;
  for (ll i = 0; i < m; i++)
    cin >> a[i] >> b[i] >> c[i], a[i] -= 1, b[i] -= 1;
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < n; j++)
      dist[i][j] = (i == j ? 0 : inf);
  for (ll i = 0; i < m; i++)
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
  for (ll i = 0; i < m; i++)
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  for (ll k = 0; k < n; k++)
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  for (ll i = 0, chk = 0; i < m; i++, chk = 0) {
    for (ll j = 0; j < n; j++)
      if (dist[j][a[i]] + c[i] == dist[j][b[i]])
        chk = 1;
    ans += chk;
  }
  cout << m - ans;
}
Problem p03837 (C++)

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

#define INF 900000000
#define LINF 9000000000000000000

typedef long long ll;
typedef pair<int, int> P;

int n, m;
int d[101][101];
int a[101], b[101], c[101];

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

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      d[i][j] = (i == j ? 0 : INF);

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
  }

  for (int i = 0; i < m; i++) {
    d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
    d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans = m;
  for (int i = 0; i < m; i++) {
    bool srt = false;
    for (int j = 0; j < n; j++)
      if (d[j][a[i]] + c[i] == d[b[i]][j])
        srt = true;
    if (srt)
      ans--;
  }

  cout << ans << endl;

  return 0;
}


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

#define INF 900000000
#define LINF 9000000000000000000

typedef long long ll;
typedef pair<int, int> P;

int n, m;
int d[101][101];
int a[1000], b[1000], c[1000];

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

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      d[i][j] = (i == j ? 0 : INF);

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
  }

  for (int i = 0; i < m; i++) {
    d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);
    d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int ans = m;
  for (int i = 0; i < m; i++) {
    bool srt = false;
    for (int j = 0; j < n; j++)
      if (d[j][a[i]] + c[i] == d[b[i]][j])
        srt = true;
    if (srt)
      ans--;
  }

  cout << ans << endl;

  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
// ------------------------------------
// Date:2018/ 2/26
// Problem:ABC 051 CandidatesOfNoShortestPaths re_d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main() {
  int N, M, cnt = 0;
  cin >> N >> M;
  vector<vector<int>> line(N, vector<int>(N, 1e4));
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  REP(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    line[--a[i]][--b[i]] = c[i];
    line[b[i]][a[i]] = c[i];
  }

  // Warshall-Floyd
  REP(h, N) {
    REP(i, N) {
      REP(j, N) { line[i][j] = min(line[i][j], line[i][h] + line[h][j]); }
    }
  }

  REP(i, M) {
    if (line[a[i]][b[i]] < c[i])
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
// ------------------------------------
// Date:2018/ 2/26
// Problem:ABC 051 CandidatesOfNoShortestPaths re_d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main() {
  int N, M, cnt = 0;
  cin >> N >> M;
  vector<vector<int>> line(N, vector<int>(N, 1e4));
  vector<int> a(M);
  vector<int> b(M);
  vector<int> c(M);
  REP(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    line[--a[i]][--b[i]] = c[i];
    line[b[i]][a[i]] = c[i];
  }

  // Warshall-Floyd
  REP(h, N) {
    REP(i, N) {
      REP(j, N) { line[i][j] = min(line[i][j], line[i][h] + line[h][j]); }
    }
  }

  REP(i, M) {
    if (line[a[i]][b[i]] < c[i])
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int MAX_V = 100; // 頂点数
vector<vector<int>> d(MAX_V, vector<int>(MAX_V, INF));
void warshall_floyd() {
  for (int k = 0; k < MAX_V; ++k)
    for (int i = 0; i < MAX_V; ++i)
      for (int j = 0; j < MAX_V; ++j)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> prev(MAX_V, vector<int>(MAX_V, INF));
  vector<int> a(n), b(n), c(n);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }

  rep(i, n) d[i][i] = 0;

  warshall_floyd();

  int ans = m;
  rep(i, m) {
    bool used = false;
    rep(j, n) {
      if (d[j][a[i]] + c[i] == d[j][b[i]])
        used = true;
    }
    if (used)
      ans--;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int MAX_V = 100; // 頂点数
vector<vector<int>> d(MAX_V, vector<int>(MAX_V, INF));
void warshall_floyd() {
  for (int k = 0; k < MAX_V; ++k)
    for (int i = 0; i < MAX_V; ++i)
      for (int j = 0; j < MAX_V; ++j)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> prev(MAX_V, vector<int>(MAX_V, INF));
  vector<int> a(m), b(m), c(m);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }

  rep(i, n) d[i][i] = 0;

  warshall_floyd();

  int ans = m;
  rep(i, m) {
    bool used = false;
    rep(j, n) {
      if (d[j][a[i]] + c[i] == d[j][b[i]])
        used = true;
    }
    if (used)
      ans--;
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(N);
  vector<vector<int>> dist(N, vector<int>(N));
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;
    B[i]--;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = 1000000000;
      }
    }
  }

  for (int i = 0; i < M; i++) {
    dist[A[i]][B[i]] = min(dist[A[i]][B[i]], C[i]);
    dist[B[i]][A[i]] = min(dist[B[i]][A[i]], C[i]);
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int res = M;
  for (int i = 0; i < M; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++) {
      if (dist[j][A[i]] + C[i] == dist[j][B[i]]) {
        flag = true;
      }
    }
    if (flag) {
      res--;
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M), C(M);
  vector<vector<int>> dist(N, vector<int>(N));
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;
    B[i]--;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = 1000000000;
      }
    }
  }

  for (int i = 0; i < M; i++) {
    dist[A[i]][B[i]] = min(dist[A[i]][B[i]], C[i]);
    dist[B[i]][A[i]] = min(dist[B[i]][A[i]], C[i]);
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int res = M;
  for (int i = 0; i < M; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++) {
      if (dist[j][A[i]] + C[i] == dist[j][B[i]]) {
        flag = true;
      }
    }
    if (flag) {
      res--;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll c[102][102], s[102], e[102], co[102];

int main() {
  ll n, m;
  cin >> n >> m;
  for (int i = 0; i < 102; i++) {
    for (int j = 0; j < 102; j++) {
      c[i][j] = c[j][i] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    s[i] = x;
    e[i] = y;
    co[i] = z;
    c[x][y] = c[y][x] = z;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < m; i++) {
    ll nows = s[i];
    ll nowe = e[i];
    ll nowcos = co[i];
    if (c[nows][nowe] != nowcos) {
      ans++;
    }
  }
  cout << ans;
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll c[102][102], s[1020], e[1020], co[1020];

int main() {
  ll n, m;
  cin >> n >> m;
  for (int i = 0; i < 102; i++) {
    for (int j = 0; j < 102; j++) {
      c[i][j] = c[j][i] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    s[i] = x;
    e[i] = y;
    co[i] = z;
    c[x][y] = c[y][x] = z;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < m; i++) {
    ll nows = s[i];
    ll nowe = e[i];
    ll nowcos = co[i];
    if (c[nows][nowe] != nowcos) {
      ans++;
    }
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll n, m, d[102][102], L[102], R[102], C[102];

void warshall_floyd() {
  for (int k = 0; k < n; k++) {     // 経由する頂点
    for (int i = 0; i < n; i++) {   // 始点
      for (int j = 0; j < n; j++) { // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < 102; i++) {
    for (int j = 0; j < 102; j++) {
      d[i][j] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    d[l][r] = d[r][l] = c;
    L[i] = l;
    R[i] = r;
    C[i] = c;
  }
  warshall_floyd();
  ll ans = m;
  for (int i = 0; i < m; i++) {
    ll nowl = L[i], nowr = R[i], nowc = C[i];
    if (d[nowl][nowr] == nowc) {
      ans--;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll n, m, d[102][102], L[1001], R[1001], C[1001];

void warshall_floyd() {
  for (int k = 0; k < n; k++) {     // 経由する頂点
    for (int i = 0; i < n; i++) {   // 始点
      for (int j = 0; j < n; j++) { // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < 102; i++) {
    for (int j = 0; j < 102; j++) {
      d[i][j] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    d[l][r] = d[r][l] = c;
    L[i] = l;
    R[i] = r;
    C[i] = c;
  }
  warshall_floyd();
  ll ans = m;
  for (int i = 0; i < m; i++) {
    ll nowl = L[i], nowr = R[i], nowc = C[i];
    if (d[nowl][nowr] == nowc) {
      ans--;
    }
  }
  cout << ans;
  return 0;
}
Problem p03837 (C++)

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

int main() {
  int n, m, ans = 0;
  const int MAX = 1 << 29;
  cin >> n >> m;
  int dist[n][n];
  int a[n], b[n], c[m];
  for (size_t i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = MAX;
    }
    dist[i][i] = 0;
  }

  for (int i = 0; i < m; i++) {
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 0; i < m; i++) {
    if (dist[a[i]][b[i]] < c[i])
      ans++;
  }
  cout << ans << endl;
}


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

int main() {
  int n, m, ans = 0;
  const int MAX = 1 << 29;
  cin >> n >> m;
  int dist[n][n];
  int a[m], b[m], c[m];
  for (size_t i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = MAX;
    }
    dist[i][i] = 0;
  }

  for (int i = 0; i < m; i++) {
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 0; i < m; i++) {
    if (dist[a[i]][b[i]] < c[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1e9);
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N, vector<int>(N, INF));
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    G[a][b] = c;
    G[b][a] = c;
    A[i] = a;
    B[i] = b;
    C[i] = c;
  }
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (G[A[i]][B[i]] != C[i])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1e9);
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N, vector<int>(N, INF));
  vector<int> A(M), B(M), C(M);
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    G[a][b] = c;
    G[b][a] = c;
    A[i] = a;
    B[i] = b;
    C[i] = c;
  }
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (G[A[i]][B[i]] != C[i])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

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

using namespace std;

const int inf = 1000000000;

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m];
  rep(i, n) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }

  int dis[n][n];
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        dis[i][j] = 0;
      else
        dis[i][j] = inf;
    }
  }

  rep(i, m) {
    dis[a[i]][b[i]] = min(dis[a[i]][b[i]], c[i]);
    dis[b[i]][a[i]] = dis[a[i]][b[i]];
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); }
    }
  }

  int res = m;
  rep(i, m) {
    bool flag = false;
    rep(j, n) {
      if (dis[j][a[i]] + c[i] == dis[j][b[i]])
        flag = true;
    }
    if (flag)
      res--;
  }

  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int inf = 1000000000;

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m];
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }

  int dis[n][n];
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        dis[i][j] = 0;
      else
        dis[i][j] = inf;
    }
  }

  rep(i, m) {
    dis[a[i]][b[i]] = min(dis[a[i]][b[i]], c[i]);
    dis[b[i]][a[i]] = dis[a[i]][b[i]];
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); }
    }
  }

  int res = m;
  rep(i, m) {
    bool flag = false;
    rep(j, n) {
      if (dis[j][a[i]] + c[i] == dis[j][b[i]])
        flag = true;
    }
    if (flag)
      res--;
  }

  cout << res << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int inf = 100000000;
  int dis[n][n];
  int a[n], b[n];
  int x[n];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> x[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        dis[i][j] = 0;
      } else {
        dis[i][j] = inf;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    dis[a[i]][b[i]] = min(dis[a[i]][b[i]], x[i]);
    dis[b[i]][a[i]] = min(dis[b[i]][a[i]], x[i]);
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int ans = m;
  for (int i = 0; i < m; i++) {
    bool sht = false;
    for (int j = 0; j < n; j++)
      if (dis[j][a[i]] + x[i] == dis[j][b[i]])
        sht = true;

    if (sht == true) {
      ans -= 1;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int inf = 100000000;
  int dis[100][100];
  int a[1000], b[1000];
  int x[1000];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> x[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        dis[i][j] = 0;
      } else {
        dis[i][j] = inf;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    dis[a[i]][b[i]] = min(dis[a[i]][b[i]], x[i]);
    dis[b[i]][a[i]] = min(dis[b[i]][a[i]], x[i]);
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int ans = m;
  for (int i = 0; i < m; i++) {
    bool sht = false;
    for (int j = 0; j < n; j++)
      if (dis[j][a[i]] + x[i] == dis[j][b[i]])
        sht = true;

    if (sht == true) {
      ans -= 1;
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N, M;
const int INF = 1LL << 55;

int main() {
  cin >> N >> M;
  int g[101][101];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      g[i][j] = 1e9;
    }
  }

  int a[101], b[101], c[101];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (g[a[i]][b[i]] != c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N, M;
const int INF = 1LL << 55;

int main() {
  cin >> N >> M;
  int g[101][101];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      g[i][j] = 1e9;
    }
  }

  int a[1001], b[1001], c[1001];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (g[a[i]][b[i]] != c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)

template <class T> using vv = vector<vector<T>>;
constexpr ll INF = 1e15;
int main() {
  int N, M;
  cin >> N >> M;

  vv<ll> cost(N, vector<ll>(N, INF));
  vi A(N), B(N), C(N);
  rep(i, M) {
    cin >> A[i] >> B[i] >> C[i];
    --A[i], --B[i];
    cost[A[i]][B[i]] = cost[B[i]][A[i]] = C[i];
  }
  rep(i, N) cost[i][i] = 0;

  rep(k, N) rep(i, N) rep(j, N) cost[i][j] =
      min(cost[i][j], cost[i][k] + cost[k][j]);

  int ans = 0;
  rep(i, M) {
    bool ok = false;
    rep(from, N) {
      rep(to, N) {
        if (cost[from][to] == cost[from][A[i]] + C[i] + cost[B[i]][to]) {
          ok = true;
          break;
        }
      }
      if (ok)
        break;
    }
    if (!ok)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)

template <class T> using vv = vector<vector<T>>;
constexpr ll INF = 1e15;
int main() {
  int N, M;
  cin >> N >> M;

  vv<ll> cost(N, vector<ll>(N, INF));
  vi A(M), B(M), C(M);
  rep(i, M) {
    cin >> A[i] >> B[i] >> C[i];
    --A[i], --B[i];
    cost[A[i]][B[i]] = cost[B[i]][A[i]] = C[i];
  }
  rep(i, N) cost[i][i] = 0;

  rep(k, N) rep(i, N) rep(j, N) cost[i][j] =
      min(cost[i][j], cost[i][k] + cost[k][j]);

  int ans = 0;
  rep(i, M) {
    bool ok = false;
    rep(from, N) {
      rep(to, N) {
        if (cost[from][to] == cost[from][A[i]] + C[i] + cost[B[i]][to]) {
          ok = true;
          break;
        }
      }
      if (ok)
        break;
    }
    if (!ok)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
using namespace std;

class WarshallFloyd {
public:
  WarshallFloyd(int sz) : size(sz), cost(size, vector<int>(size, INT_MAX / 2)) {
    for (int i = 0; i < size; i++)
      cost[i][i] = 0;
  }
  void calc(void) {
    for (int k = 0; k < size; k++)
      for (int i = 0; i < size; i++)
        for (int j = 0; j < size; j++)
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
  }
  void setCost(int src, int dst, int c) {
    cost[src][dst] = c;
    cost[dst][src] = c;
  }
  int getCost(int src, int dst) { return cost[src][dst]; }

private:
  const int size;
  vector<vector<int>> cost;
};

int main(void) {
  int N, M;
  cin >> N >> M;

  WarshallFloyd wf(N);
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];

    a[i]--;
    b[i]--;

    wf.setCost(a[i], b[i], c[i]);
  }

  wf.calc();

  int ret = M;
  for (int i = 0; i < M; i++) {
    bool used = false;
    for (int j = 0; j < N; j++)
      if (wf.getCost(j, b[i]) - wf.getCost(j, a[i]) == c[i])
        used = true;

    if (used == true)
      ret--;
  }

  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
using namespace std;

class WarshallFloyd {
public:
  WarshallFloyd(int sz) : size(sz), cost(size, vector<int>(size, INT_MAX / 2)) {
    for (int i = 0; i < size; i++)
      cost[i][i] = 0;
  }
  void calc(void) {
    for (int k = 0; k < size; k++)
      for (int i = 0; i < size; i++)
        for (int j = 0; j < size; j++)
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
  }
  void setCost(int src, int dst, int c) {
    cost[src][dst] = c;
    cost[dst][src] = c;
  }
  int getCost(int src, int dst) { return cost[src][dst]; }

private:
  const int size;
  vector<vector<int>> cost;
};

int main(void) {
  int N, M;
  cin >> N >> M;

  WarshallFloyd wf(N);
  vector<int> a(M), b(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];

    a[i]--;
    b[i]--;

    wf.setCost(a[i], b[i], c[i]);
  }

  wf.calc();

  int ret = M;
  for (int i = 0; i < M; i++) {
    bool used = false;
    for (int j = 0; j < N; j++)
      if (wf.getCost(j, b[i]) - wf.getCost(j, a[i]) == c[i])
        used = true;

    if (used == true)
      ret--;
  }

  cout << ret << endl;

  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9;

struct Edge {
  int from, to, cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Edge> edge(N);
  vector<vector<int>> dist(N, vector<int>(N, INF));
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[i].from = a;
    edge[i].to = b;
    edge[i].cost = c;
    dist[a][b] = dist[b][a] = c;
  }

  // ワーシャルフロイド法
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (edge[i].cost != dist[edge[i].from][edge[i].to])
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9;

struct Edge {
  int from, to, cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Edge> edge(M);
  vector<vector<int>> dist(N, vector<int>(N, INF));
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[i].from = a;
    edge[i].to = b;
    edge[i].cost = c;
    dist[a][b] = dist[b][a] = c;
  }

  // ワーシャルフロイド法
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (edge[i].cost != dist[edge[i].from][edge[i].to])
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAXN 110
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ss second
#define ff first

using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
int adj[MAXN][MAXN];

void solve(int n) {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        adj[i][j] = min(adj[i][k] + adj[k][j], adj[i][j]);
      }
    }
  }
}

void init(int n) {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      adj[i][j] = mod;
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;

  init(n);
  vector<pair<int, pii>> edge(n);

  for (int i = 0; i < m; i++) {
    cin >> edge[i].ss.ff >> edge[i].ss.ss >> edge[i].ff;
    adj[edge[i].ss.ff][edge[i].ss.ss] = adj[edge[i].ss.ss][edge[i].ss.ff] =
        edge[i].ff;
  }

  solve(n);

  int ans = 0;

  for (int i = 0; i < m; i++) {
    int x = edge[i].ss.ff, y = edge[i].ss.ss, c = edge[i].ff;
    if (adj[x][y] != c)
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAXN 110
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ss second
#define ff first

using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
int adj[MAXN][MAXN];

void solve(int n) {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        adj[i][j] = min(adj[i][k] + adj[k][j], adj[i][j]);
      }
    }
  }
}

void init(int n) {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      adj[i][j] = mod;
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;

  init(n);
  vector<pair<int, pii>> edge(m);

  for (int i = 0; i < m; i++) {
    cin >> edge[i].ss.ff >> edge[i].ss.ss >> edge[i].ff;
    adj[edge[i].ss.ff][edge[i].ss.ss] = adj[edge[i].ss.ss][edge[i].ss.ff] =
        edge[i].ff;
  }

  solve(n);

  int ans = 0;

  for (int i = 0; i < m; i++) {
    int x = edge[i].ss.ff, y = edge[i].ss.ss, c = edge[i].ff;
    if (adj[x][y] != c)
      ans++;
  }

  cout << ans << endl;
  return 0;
}