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

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

const LL inf = 1123456789;

std::vector<std::vector<LL>> dist;
std::set<std::pair<LL, LL>> res;
void warshall_floyd(LL V) {
  for (LL k = 0; k < V; ++k) {
    for (LL i = 0; i < V; ++i) {
      for (LL j = 0; j < V; ++j) {
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
          if (dist[i][j] != inf)
            res.insert(std::make_pair(std::min(i, j), std::max(i, j)));
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
}

int main() {
  LL N, M;
  in >> N >> M;
  std::vector<LL> a(M), b(M), c(M);
  rep(i, M) in >> a[i] >> b[i] >> c[i];
  rep(i, M) if (a[i] > b[i]) std::swap(a[i], b[i]);

  dist.resize(N);
  rep(i, dist.size()) dist[i].resize(N, inf);
  rep(i, N) dist[i][i] = 0;
  rep(i, M) dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  warshall_floyd(N);

  LL ans = 0;
  for (auto e : res) {
    rep(i, M) {
      if (e.first == a[i] && e.second == b[i]) {
        ++ans;
        break;
      }
    }
  }

  out << ans << std::endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

const LL inf = 1123456789;

std::vector<std::vector<LL>> dist;
std::set<std::pair<LL, LL>> res;
void warshall_floyd(LL V) {
  for (LL k = 0; k < V; ++k) {
    for (LL i = 0; i < V; ++i) {
      for (LL j = 0; j < V; ++j) {
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
          if (dist[i][j] != inf)
            res.insert(std::make_pair(std::min(i, j), std::max(i, j)));
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
}

int main() {
  LL N, M;
  in >> N >> M;
  std::vector<LL> a(M), b(M), c(M);
  rep(i, M) in >> a[i] >> b[i] >> c[i];
  rep(i, M) {
    if (a[i] > b[i])
      std::swap(a[i], b[i]);
    --a[i];
    --b[i];
  }

  dist.resize(N);
  rep(i, dist.size()) dist[i].resize(N, inf);
  rep(i, N) dist[i][i] = 0;
  rep(i, M) dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  warshall_floyd(N);

  LL ans = 0;
  for (auto e : res) {
    rep(i, M) {
      if (e.first == a[i] && e.second == b[i]) {
        ++ans;
        break;
      }
    }
  }

  out << ans << std::endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;

#define INF (1 << 29)

int n, m, res;
int a[108], b[108], c[108];
int dist[108000];
vector<P> edge[108];
void dijkstra(int s) {
  for (int i = 0; i < n; i++)
    dist[i] = INF;
  dist[s] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(P(0, s));

  while (!pq.empty()) {
    P tmp = pq.top();
    pq.pop();
    int from = tmp.second;
    int d = tmp.first;
    if (dist[from] < d)
      continue;
    for (int i = 0; i < edge[from].size(); i++) {
      int to = edge[from][i].first;
      int c = edge[from][i].second;
      if (dist[from] + c < dist[to]) {
        dist[to] = dist[from] + c;
        pq.push(P(dist[to], to));
      }
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    edge[a[i]].push_back(P(b[i], c[i]));
    edge[b[i]].push_back(P(a[i], c[i]));
  }
  for (int i = 0; i < m; i++) {
    dijkstra(a[i]);
    if (dist[b[i]] != c[i])
      res++;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;

#define INF (1 << 29)

int n, m, res;
int a[1080], b[1080], c[1080];
int dist[108];
vector<P> edge[108];
void dijkstra(int s) {
  for (int i = 0; i < n; i++)
    dist[i] = INF;
  dist[s] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(P(0, s));

  while (!pq.empty()) {
    P tmp = pq.top();
    pq.pop();
    int from = tmp.second;
    int d = tmp.first;
    if (dist[from] < d)
      continue;
    for (int i = 0; i < edge[from].size(); i++) {
      int to = edge[from][i].first;
      int c = edge[from][i].second;
      if (dist[from] + c < dist[to]) {
        dist[to] = dist[from] + c;
        pq.push(P(dist[to], to));
      }
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    edge[a[i]].push_back(P(b[i], c[i]));
    edge[b[i]].push_back(P(a[i], c[i]));
  }
  for (int i = 0; i < m; i++) {
    dijkstra(a[i]);
    if (dist[b[i]] != c[i])
      res++;
  }
  cout << res << endl;
  return 0;
}
Problem p03837 (C++)

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

int N, M;
vector<int> a(110), b(110), c(110);
int d[110][110];

int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      d[i][j] = 100000000;
    }
  }
  for (int i = 1; i <= M; i++) {
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }
  for (int k = 1; k <= N; k++) {
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (d[a[i]][b[i]] != c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int N, M;
vector<int> a(1010), b(1010), c(1010);
int d[110][110];

int main() {
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      d[i][j] = 100000000;
    }
  }
  for (int i = 1; i <= M; i++) {
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }
  for (int k = 1; k <= N; k++) {
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (d[a[i]][b[i]] != c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)

typedef long long ll;
using namespace std;
const int INF = 1 << 29;
struct Edge {
  int to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

set<pair<int, int>> isUsed;

void dijkstra(const Graph &G, int s) {
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      q;
  vector<ll> d((int)G.size(), INF);
  vector<vector<int>> path((int)G.size());

  q.push({0, s});
  d[s] = 0;

  while (!q.empty()) {
    auto cur = q.top();
    q.pop();
    ll cur_dist = cur.second;
    int v = cur.first;
    if (cur_dist > d[v])
      continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push({d[v] + e.cost, e.to});

        path[e.to].clear();
        path[e.to].pb(v);
      } else if (d[e.to] == d[v] + e.cost) {
        path[e.to].pb(v);
      }
    }
  }

  rep(v, (int)G.size()) {
    for (auto u : path[v]) {
      isUsed.insert(mp(min(u, v), max(u, v)));
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  Graph G(n);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].pb(Edge{b, c});
    G[b].pb(Edge{a, c});
  }

  // 任意の点開始の最短経路を求める
  rep(i, n) { dijkstra(G, i); }
  cout << m - (int)isUsed.size() << endl;
  //   system("pause");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)

typedef long long ll;
using namespace std;
const int INF = 1 << 29;
struct Edge {
  int to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

set<pair<int, int>> isUsed;

void dijkstra(const Graph &G, int s) {
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      q;
  vector<ll> d((int)G.size(), INF);
  vector<vector<int>> path((int)G.size());

  q.push({0, s});
  d[s] = 0;

  while (!q.empty()) {
    auto cur = q.top();
    q.pop();
    ll cur_dist = cur.first;
    int v = cur.second;
    if (cur_dist > d[v])
      continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push({d[v] + e.cost, e.to});

        path[e.to].clear();
        path[e.to].pb(v);
      } else if (d[e.to] == d[v] + e.cost) {
        path[e.to].pb(v);
      }
    }
  }

  rep(v, (int)G.size()) {
    for (auto u : path[v]) {
      isUsed.insert(mp(min(u, v), max(u, v)));
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  Graph G(n);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].pb(Edge{b, c});
    G[b].pb(Edge{a, c});
  }

  // 任意の点開始の最短経路を求める
  rep(i, n) { dijkstra(G, i); }
  cout << m - (int)isUsed.size() << endl;
  //   system("pause");
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n), c(n);
  vector<vector<ll>> dist(n, vector<ll>(n));

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

  rep(i, 0, n) {
    rep(j, 0, n) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = INF;
    }
  }

  rep(i, 0, m) {
    chmin(dist[a[i]][b[i]], c[i]);
    chmin(dist[b[i]][a[i]], c[i]);
  }

  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n)
      chmin(dist[i][j], dist[i][k] + dist[k][j]);

  ll ans = m;
  rep(i, 0, m) {
    bool is_shortest = false;
    rep(j, 0, n) if (dist[j][a[i]] + c[i] == dist[j][b[i]]) is_shortest = true;
    if (is_shortest)
      ans--;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m), c(m);
  vector<vector<ll>> dist(n, vector<ll>(n));

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

  rep(i, 0, n) {
    rep(j, 0, n) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = INF;
    }
  }

  rep(i, 0, m) {
    chmin(dist[a[i]][b[i]], c[i]);
    chmin(dist[b[i]][a[i]], c[i]);
  }

  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n)
      chmin(dist[i][j], dist[i][k] + dist[k][j]);

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

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int dist[110][110];
int a[110], b[110], c[110];
int n, m;
int ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      dist[i][j] = 1e9;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", a + i, b + i, c + i);
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      if (i == k)
        continue;
      for (int j = 1; j <= n; j++) {
        if (i == j || k == j)
          continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (dist[a[i]][b[i]] != c[i])
      ans++;
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int dist[110][110];
int a[10010], b[10010], c[10010];
int n, m;
int ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      dist[i][j] = 1e9;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", a + i, b + i, c + i);
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      if (i == k)
        continue;
      for (int j = 1; j <= n; j++) {
        if (i == j || k == j)
          continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (dist[a[i]][b[i]] != c[i])
      ans++;
  }
  printf("%d", ans);
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
// C++ Program for Floyd Warshall Algorithm
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 999999999

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  int adj_matrix[n][n];
  REP(i, n) {
    REP(j, n) {
      if (i == j) {
        adj_matrix[i][j] = 0;
      } else {
        adj_matrix[i][j] = INF;
      }
    }
  }
  int ai[m];
  int bi[m];
  int ci[m];
  REP(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    adj_matrix[a][b] = c;
    adj_matrix[b][a] = c;
    ai[i] = a;
    bi[i] = b;
    ci[i] = c;
  }

  int dist[n][n];

  REP(i, n) {
    REP(j, n) { dist[i][j] = adj_matrix[i][j]; }
  }

  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(k, m) {
    bool shortest = false;
    REP(i, n) {
      if (dist[i][ai[k]] + ci[k] == dist[i][bi[k]]) {
        shortest = true;
        break;
      }
    }
    if (shortest) {
      ans--;
    }
  }
  cout << ans << endl;
}

Fixed submission:
// C++ Program for Floyd Warshall Algorithm
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 999999999

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  int adj_matrix[n][n];
  REP(i, n) {
    REP(j, n) {
      if (i == j) {
        adj_matrix[i][j] = 0;
      } else {
        adj_matrix[i][j] = INF;
      }
    }
  }
  int ai[m];
  int bi[m];
  int ci[m];
  REP(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    adj_matrix[a][b] = c;
    adj_matrix[b][a] = c;
    ai[i] = a;
    bi[i] = b;
    ci[i] = c;
  }

  int dist[n][n];

  REP(i, n) {
    REP(j, n) { dist[i][j] = adj_matrix[i][j]; }
  }

  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(k, m) {
    bool shortest = false;
    REP(i, n) {
      if (dist[i][ai[k]] + ci[k] == dist[i][bi[k]]) {
        shortest = true;
        break;
      }
    }
    if (shortest) {
      ans--;
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> dist(n, std::vector<int>(n));
  rep(i, n) rep(j, n) {
    { dist[i][j] = INF; }
  }
  rep(i, n) dist[i][i] = 0;
  std::vector<int> a(n), b(n), c(n);
  rep(i, m) {
    int aa, bb, cc;
    std::cin >> aa >> bb >> cc;
    aa--;
    bb--;
    dist[aa][bb] = cc;
    dist[bb][aa] = cc;
    a[i] = aa;
    b[i] = bb;
    c[i] = cc;
  }
  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 counter = 0;
  rep(i, m) if (c[i] > dist[a[i]][b[i]]) counter++;
  std::cout << counter << std::endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> dist(n, std::vector<int>(n));
  rep(i, n) rep(j, n) {
    { dist[i][j] = INF; }
  }
  rep(i, n) dist[i][i] = 0;
  std::vector<int> a(m), b(m), c(m);
  rep(i, m) {
    int aa, bb, cc;
    std::cin >> aa >> bb >> cc;
    aa--;
    bb--;
    dist[aa][bb] = cc;
    dist[bb][aa] = cc;
    a[i] = aa;
    b[i] = bb;
    c[i] = cc;
  }
  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 counter = 0;
  rep(i, m) if (c[i] > dist[a[i]][b[i]]) counter++;
  std::cout << counter << std::endl;
}
Problem p03837 (C++)

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

int main() {

  int n, m;

  cin >> n >> m;

  int table[n + 1][n + 1];

  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      table[i][j] = 10000000;
    }
  }

  for (int i = 0; i < n + 1; i++) {
    table[i][i] = 0;
  }

  int to[n], from[n], cost[n];

  for (int i = 0; i < m; i++) {

    int a, b, c;

    cin >> a >> b >> c;

    to[i] = a;
    from[i] = b;
    cost[i] = c;

    table[a][b] = c;
    table[b][a] = c;
  }

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

  int ans = 0;

  for (int i = 0; i < m; i++) {
    bool used = false;
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (table[j][k] == table[j][to[i]] + cost[i] + table[from[i]][k]) {
          used = true;
        }
        if (table[j][k] == table[j][from[i]] + cost[i] + table[to[i]][k]) {
          used = true;
        }
      }
    }
    if (!used) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {

  int n, m;

  cin >> n >> m;

  int table[n + 1][n + 1];

  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      table[i][j] = 10000000;
    }
  }

  for (int i = 0; i < n + 1; i++) {
    table[i][i] = 0;
  }

  int to[m], from[m], cost[m];

  for (int i = 0; i < m; i++) {

    int a, b, c;

    cin >> a >> b >> c;

    to[i] = a;
    from[i] = b;
    cost[i] = c;

    table[a][b] = c;
    table[b][a] = c;
  }

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

  int ans = 0;

  for (int i = 0; i < m; i++) {
    bool used = false;
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (table[j][k] == table[j][to[i]] + cost[i] + table[from[i]][k]) {
          used = true;
        }
        if (table[j][k] == table[j][from[i]] + cost[i] + table[to[i]][k]) {
          used = true;
        }
      }
    }
    if (!used) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03837 (C++)

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j, k;
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> graph(n, vector<ll>(n, 1e9));
  for (i = 0; i < n; ++i) {
    graph.at(i).at(i) = 0;
  }
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  for (i = 0; i < m; ++i) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    --a.at(i);
    --b.at(i);
    graph.at(a.at(i)).at(b.at(i)) = c.at(i);
    graph.at(b.at(i)).at(a.at(i)) = c.at(i);
  }
  rep(k, n) {
    for (i = 0; i < n; ++i) {
      rep(j, n) {
        graph.at(i).at(j) =
            min(graph.at(i).at(j), graph.at(i).at(k) + graph.at(k).at(j));
      }
    }
  }
  ll ans = 0;
  for (i = 0; i < m; ++i) {
    if (graph.at(a.at(i)).at(b.at(i)) < c.at(i))
      ++ans;
  }
  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for (i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {
  ll i, j, k;
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> graph(n, vector<ll>(n, 1e9));
  for (i = 0; i < n; ++i) {
    graph.at(i).at(i) = 0;
  }
  vector<ll> a(m);
  vector<ll> b(m);
  vector<ll> c(m);
  for (i = 0; i < m; ++i) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    --a.at(i);
    --b.at(i);
    graph.at(a.at(i)).at(b.at(i)) = c.at(i);
    graph.at(b.at(i)).at(a.at(i)) = c.at(i);
  }
  rep(k, n) {
    for (i = 0; i < n; ++i) {
      rep(j, n) {
        graph.at(i).at(j) =
            min(graph.at(i).at(j), graph.at(i).at(k) + graph.at(k).at(j));
      }
    }
  }
  ll ans = 0;
  for (i = 0; i < m; ++i) {
    if (graph.at(a.at(i)).at(b.at(i)) < c.at(i))
      ++ans;
  }
  cout << ans << endl;

  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define dump(x) cout << (x) << endl;
typedef long long Int;

Int mod = 1e9 + 7;
Int MOD = 998244353;

Int n, m;
Int cost[101][101];
Int d[101];

void dijkstra(Int x) {
  for (Int i = 1; i <= n; i++)
    d[i] = 1e9;
  d[x] = 0;
  vector<bool> used(n + 1, false);
  while (true) {
    Int v = -1;
    for (Int i = 1; i <= n; i++) {
      if (!used[i] && (v == -1 || d[i] < d[v]))
        v = i;
    }
    if (v == -1)
      break;
    used[v] = true;
    for (Int i = 1; i <= n; i++) {
      // cout << d[i] << " " << d[v] + cost[v][i] << endl;
      d[i] = min(d[i], d[v] + cost[v][i]);
    }
  }
}

int main() {
  cin >> n >> m;
  vector<Int> a(n), b(n), c(n);
  for (Int i = 1; i <= n; i++) {
    for (Int j = 1; j <= n; j++) {
      cost[i][j] = (i == j) ? 0 : 1e9;
    }
  }
  for (Int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    cost[a[i]][b[i]] = cost[b[i]][a[i]] = c[i];
  }
  vector<bool> is(m, false);
  for (Int i = 1; i <= n; i++) {
    dijkstra(i);
    for (Int j = 0; j < m; j++) {
      if ((d[a[j]] + c[j] == d[b[j]]) || (d[a[j]] == d[b[j]] + c[j]))
        is[j] = true;
    }
  }
  Int res = 0;
  for (Int i = 0; i < m; i++) {
    if (!is[i])
      res++;
  }
  dump(res);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define dump(x) cout << (x) << endl;
typedef long long Int;

Int mod = 1e9 + 7;
Int MOD = 998244353;

Int n, m;
Int cost[101][101];
Int d[101];

void dijkstra(Int x) {
  for (Int i = 1; i <= n; i++)
    d[i] = 1e9;
  d[x] = 0;
  vector<bool> used(n + 1, false);
  while (true) {
    Int v = -1;
    for (Int i = 1; i <= n; i++) {
      if (!used[i] && (v == -1 || d[i] < d[v]))
        v = i;
    }
    if (v == -1)
      break;
    used[v] = true;
    for (Int i = 1; i <= n; i++) {
      // cout << d[i] << " " << d[v] + cost[v][i] << endl;
      d[i] = min(d[i], d[v] + cost[v][i]);
    }
  }
}

int main() {
  cin >> n >> m;
  vector<Int> a(m), b(m), c(m);
  for (Int i = 1; i <= n; i++) {
    for (Int j = 1; j <= n; j++) {
      cost[i][j] = (i == j) ? 0 : 1e9;
    }
  }
  for (Int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    cost[a[i]][b[i]] = cost[b[i]][a[i]] = c[i];
  }
  vector<bool> is(m, false);
  for (Int i = 1; i <= n; i++) {
    dijkstra(i);
    for (Int j = 0; j < m; j++) {
      if ((d[a[j]] + c[j] == d[b[j]]) || (d[a[j]] == d[b[j]] + c[j]))
        is[j] = true;
    }
  }
  Int res = 0;
  for (Int i = 0; i < m; i++) {
    if (!is[i])
      res++;
  }
  dump(res);
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define mp make_pair
#define fr(i, n) for (int i = 0; i < n; i++)
#define Fr(i, n) for (int i = 0; i++ < n;)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)
#define iFr(i, n) for (int i = n; i > 0; i--)

int main() {
  ll n, m, a[110], b[110], c[110][110] = {}, d[110][110] = {}, ans = 0;
  cin >> n >> m;
  Fr(i, n) Fr(j, n) if (i != j) d[i][j] = 10000;
  Fr(i, m) {
    cin >> a[i] >> b[i];
    cin >> c[a[i]][b[i]];
    c[b[i]][a[i]] = c[a[i]][b[i]];
    d[a[i]][b[i]] = c[a[i]][b[i]];
    d[b[i]][a[i]] = c[a[i]][b[i]];
  }
  Fr(k, n) Fr(i, n) Fr(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  Fr(i, m) if (c[a[i]][b[i]] > d[a[i]][b[i]]) ans++;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define mp make_pair
#define fr(i, n) for (int i = 0; i < n; i++)
#define Fr(i, n) for (int i = 0; i++ < n;)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)
#define iFr(i, n) for (int i = n; i > 0; i--)

int main() {
  ll n, m, a[1010], b[1010], c[110][110] = {}, d[110][110] = {}, ans = 0;
  cin >> n >> m;
  Fr(i, n) Fr(j, n) if (i != j) d[i][j] = 10000;
  Fr(i, m) {
    cin >> a[i] >> b[i];
    cin >> c[a[i]][b[i]];
    c[b[i]][a[i]] = c[a[i]][b[i]];
    d[a[i]][b[i]] = c[a[i]][b[i]];
    d[b[i]][a[i]] = c[a[i]][b[i]];
  }
  Fr(k, n) Fr(i, n) Fr(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  Fr(i, m) if (c[a[i]][b[i]] > d[a[i]][b[i]]) ans++;
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#define REP(a, b, c) for (int(a) = (b); (a) < (c); ++a)
using namespace std;
typedef tuple<int, int, int> tiii;
const int INF = 1 << 29;
int N, M;
int A[100][100];
int a, b, c;
queue<tiii> q;
int main(void) {
  cin >> N >> M;
  fill_n(A[0], (N + 1) * (N + 1), INF);
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    A[a][b] = A[b][a] = c;
    q.push(tiii(a, b, c));
  }
  REP(k, 0, N) REP(i, 0, N) REP(j, 0, N) {
    A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
  }
  int ans = M;
  while (!q.empty()) {
    tie(a, b, c) = q.front();
    q.pop();
    if (A[a][b] == c)
      --ans;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#define REP(a, b, c) for (int(a) = (b); (a) < (c); ++a)
using namespace std;
typedef tuple<int, int, int> tiii;
const int INF = 1 << 29;
int N, M;
int A[100][100];
int a, b, c;
queue<tiii> q;
int main(void) {
  cin >> N >> M;
  fill(A[0], A[N], INF);
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    A[a][b] = A[b][a] = c;
    q.push(tiii(a, b, c));
  }
  REP(k, 0, N) REP(i, 0, N) REP(j, 0, N) {
    A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
  }
  int ans = M;
  while (!q.empty()) {
    tie(a, b, c) = q.front();
    q.pop();
    if (A[a][b] == c)
      --ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

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

typedef long long ll;
typedef long double ld;

const int INF = 1000000000;

bool cand[1005];
int n;
int dist[100];
vector<pair<int, int>> graf[105];

struct edge {
  int a, b, c;
};

vector<edge> edges;

void dijkstra(int root) {
  set<pair<int, int>> q;
  for (int i = 1; i <= n; i++)
    dist[i] = INF;
  dist[root] = 0;
  q.insert({0, root});
  while (!q.empty()) {
    pair<int, int> par = *q.begin();
    q.erase(q.begin());
    int v = par.second;
    for (auto p : graf[v]) {
      if (dist[p.first] > dist[v] + p.second) {
        q.erase({dist[p.first], p.first});
        dist[p.first] = dist[v] + p.second;
        q.insert({dist[p.first], p.first});
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;

  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.push_back({a, b, c});
    graf[a].push_back({b, c});
    graf[b].push_back({a, c});
  }
  for (int i = 1; i <= n; i++) {
    dijkstra(i);
    for (int j = 0; j < m; j++) {
      if (!cand[j] && edges[j].c == abs(dist[edges[j].a] - dist[edges[j].b])) {
        cand[j] = 1;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    cnt += 1 - cand[i];
  }
  cout << cnt;
  return 0;
}


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

typedef long long ll;
typedef long double ld;

const int INF = 1000000000;

bool cand[1005];
int n;
int dist[105];
vector<pair<int, int>> graf[105];

struct edge {
  int a, b, c;
};

vector<edge> edges;

void dijkstra(int root) {
  set<pair<int, int>> q;
  for (int i = 1; i <= n; i++)
    dist[i] = INF;
  dist[root] = 0;
  q.insert({0, root});
  while (!q.empty()) {
    pair<int, int> par = *q.begin();
    q.erase(q.begin());
    int v = par.second;
    for (auto p : graf[v]) {
      if (dist[p.first] > dist[v] + p.second) {
        q.erase({dist[p.first], p.first});
        dist[p.first] = dist[v] + p.second;
        q.insert({dist[p.first], p.first});
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;

  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.push_back({a, b, c});
    graf[a].push_back({b, c});
    graf[b].push_back({a, c});
  }
  for (int i = 1; i <= n; i++) {
    dijkstra(i);
    for (int j = 0; j < m; j++) {
      if (!cand[j] && edges[j].c == abs(dist[edges[j].a] - dist[edges[j].b])) {
        cand[j] = 1;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    cnt += 1 - cand[i];
  }
  cout << cnt;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  const int inf = 1e+9;
  int n, m;
  cin >> n >> m;

  int a[n], b[n], c[n], dist[n][n];
  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] = inf;
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    dist[a[i]][b[i]] = c[i];
    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 ans = m;
  for (int i = 0; i < m; i++) {
    bool shortest = false;
    for (int j = 0; j < n; j++) {
      if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
        shortest = true;
      }
    }
    if (shortest) {
      ans--;
    }
  }

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  const int inf = 1e+9;
  int n, m;
  cin >> n >> m;

  int a[1000], b[1000], c[1000], dist[100][100];
  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] = inf;
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    dist[a[i]][b[i]] = c[i];
    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 ans = m;
  for (int i = 0; i < m; i++) {
    bool shortest = false;
    for (int j = 0; j < n; j++) {
      if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
        shortest = true;
      }
    }
    if (shortest) {
      ans--;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(), (a).end()

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll keta(ll n) {
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  int G[n][n];
  rep(i, n) rep(j, n) {
    if (i == j)
      G[i][j] = 0;
    else
      G[i][j] = G[j][i] = 1e9;
  }
  vi a(n), b(n), c(n);
  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) {
    bool ok = true;
    rep(s, n) if (G[s][b[i]] == G[s][a[i]] + c[i]) ok = false;
    if (ok)
      ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(), (a).end()

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll keta(ll n) {
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  int G[n][n];
  rep(i, n) rep(j, n) {
    if (i == j)
      G[i][j] = 0;
    else
      G[i][j] = G[j][i] = 1e9;
  }
  vi a(m), b(m), c(m);
  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) {
    bool ok = true;
    rep(s, n) if (G[s][b[i]] == G[s][a[i]] + c[i]) ok = false;
    if (ok)
      ans++;
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  int a[100], b[100], c[100];
  int dist[100][100];
  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) {
      dist[i][j] = INF;
    }
    dist[i][i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    dist[a[i]][b[i]] = c[i];
    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 ans = M;
  for (int i = 0; i < M; ++i) {
    for (int s = 0; s < N; ++s) {
      if (dist[s][a[i]] + c[i] == dist[s][b[i]]) {
        --ans;
        break;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int a[1000], b[1000], c[1000];
  int dist[100][100];
  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) {
      dist[i][j] = INF;
    }
    dist[i][i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    dist[a[i]][b[i]] = c[i];
    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 ans = M;
  for (int i = 0; i < M; ++i) {
    for (int s = 0; s < N; ++s) {
      if (dist[s][a[i]] + c[i] == dist[s][b[i]]) {
        --ans;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.1415926535897932384626433832;
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m, dist[105][105] = {}, ans = 0, a[105] = {}, b[105] = {}, c[105] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        dist[i][j] = inf;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  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]);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (dist[a[i]][b[i]] < c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.1415926535897932384626433832;
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m, dist[105][105] = {}, ans = 0, a[5005] = {}, b[5005] = {},
            c[5005] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        dist[i][j] = inf;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }
  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]);
      }
    }
  }
  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 "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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;
}

const ll INF = 2e9;

ll dist[105][105];

void warchall_floyd(int N) {
  rep(k, N) rep(i, N) {
    if (dist[i][k] == INF)
      continue;
    rep(j, N) {
      if (dist[k][j] == INF)
        continue;
      chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  rep(i, n) {
    rep(j, n) dist[i][j] = INF;
    dist[i][i] = 0;
  }
  vector<int> a(n), b(n), c(n);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }
  warchall_floyd(n);
  int ans = 0;
  rep(i, m) {
    if (dist[a[i]][b[i]] == c[i])
      continue;
    if (dist[b[i]][a[i]] == c[i])
      continue;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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;
}

const ll INF = 2e9;

ll dist[105][105];

void warchall_floyd(int N) {
  rep(k, N) rep(i, N) {
    if (dist[i][k] == INF)
      continue;
    rep(j, N) {
      if (dist[k][j] == INF)
        continue;
      chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  rep(i, n) {
    rep(j, n) dist[i][j] = INF;
    dist[i][i] = 0;
  }
  vector<int> a(m), b(m), c(m);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }
  warchall_floyd(n);
  int ans = 0;
  rep(i, m) {
    if (dist[a[i]][b[i]] == c[i])
      continue;
    if (dist[b[i]][a[i]] == c[i])
      continue;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));

ll n, m, li[110][110], a[110], b[110], c[110];

int main() {
  cin >> n >> m;
  REP(i, 0, n) REP(j, 0, n) li[i][j] = li[j][i] = LINF;
  REP(i, 0, n) li[i][i] = 0;
  REP(i, 0, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    li[a[i]][b[i]] = li[b[i]][a[i]] = c[i];
  }
  REP(k, 0, n)
  REP(i, 0, n) REP(j, 0, n) li[i][j] = min(li[i][j], li[i][k] + li[k][j]);

  int cou = 0;
  REP(i, 0, m) {
    bool f = true;
    REP(j, 0, n) {
      REP(k, 0, n) {
        if (li[j][k] == li[j][a[i]] + c[i] + li[b[i]][k])
          f = false;
      }
    }
    if (f)
      cou++;
  }

  cout << cou << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));

ll n, m, li[110][110], a[1010], b[1010], c[1010];

int main() {
  cin >> n >> m;
  REP(i, 0, n) REP(j, 0, n) li[i][j] = li[j][i] = LINF;
  REP(i, 0, n) li[i][i] = 0;
  REP(i, 0, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    li[a[i]][b[i]] = li[b[i]][a[i]] = c[i];
  }
  REP(k, 0, n)
  REP(i, 0, n) REP(j, 0, n) li[i][j] = min(li[i][j], li[i][k] + li[k][j]);

  int cou = 0;
  REP(i, 0, m) {
    bool f = true;
    REP(j, 0, n) {
      REP(k, 0, n) {
        if (li[j][k] == li[j][a[i]] + c[i] + li[b[i]][k])
          f = false;
      }
    }
    if (f)
      cou++;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, i0, n) for (int(i) = (i0); (i) < (n); (i)++)
#define FORR(i, i0, n) for (int(i) = (n)-1; (i) >= (i0); (i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int, int> P;
using namespace std;
using ll = long long;

int main() {
  const int inf = 100000000;
  int n, m;
  cin >> n >> m;
  int a[1000], b[1000], c[1000], dist[100][100];

  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  rep(i, n) {
    rep(j, m) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = inf;
    }
  }

  rep(i, m) {
    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 shortest = false;
    rep(j, n) if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
    if (shortest == true) {
      ans--;
    }
  }
  cout << ans;
  rn 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, i0, n) for (int(i) = (i0); (i) < (n); (i)++)
#define FORR(i, i0, n) for (int(i) = (n)-1; (i) >= (i0); (i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int, int> P;
using namespace std;
using ll = long long;

int main() {
  const int inf = 100000000;
  int n, m;
  cin >> n >> m;
  int a[1000], b[1000], c[1000], dist[100][100];

  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = inf;
    }
  }

  rep(i, m) {
    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 shortest = false;
    rep(j, n) if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
    if (shortest == true) {
      ans--;
    }
  }
  cout << ans;
  rn 0;
}
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>

int abs(int x) { return x > 0 ? x : -x; }

int main() {
  int A, B;
  while (1) {
    scanf("%d%d", &A, &B);
    if (A <= B) {
      if ((A < 0 && B <= 0) || (A >= 0))
        printf("%d", B - A);
      else //-10 11
        printf("%d", abs(abs(A) - abs(B)) + 1);
    } else {
      if ((A < 0) || (A > 0 && B > 0)) //-10 -20 20 10
        printf("%d", A - B + 2);
      else // 10 -20  20 -10
        printf("%d", abs(abs(B) - abs(A)) + 1);
    }
    puts("");
  }
}


Fixed submission:
#include <cstdio>

int abs(int x) { return x > 0 ? x : -x; }

int main() {
  int A, B;
  scanf("%d%d", &A, &B);
  if (A <= B) {
    if ((A < 0 && B <= 0) || (A >= 0))
      printf("%d", B - A);
    else //-10 11
      printf("%d", abs(abs(A) - abs(B)) + 1);
  } else {
    if ((A < 0) || (A > 0 && B > 0)) //-10 -20 20 10
      printf("%d", A - B + 2);
    else // 10 -20  20 -10
      printf("%d", abs(abs(B) - abs(A)) + 1);
  }
}