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

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

int main(void) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  const int dx = tx - sx, dy = ty - tx;

  // Path 1
  cout << string(dy, 'U') << string(dx, 'R');

  // Path 2
  cout << string(dy, 'D') << string(dx, 'L');

  // Path 3
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';

  // Path 4
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

  // EndLine
  cout << endl;

  return 0;
}

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

int main(void) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  const int dx = tx - sx, dy = ty - sy;

  // Path 1
  cout << string(dy, 'U') << string(dx, 'R');

  // Path 2
  cout << string(dy, 'D') << string(dx, 'L');

  // Path 3
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';

  // Path 4
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

  // EndLine
  cout << endl;

  return 0;
}
Problem p03836 (C++)

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  const int dx = tx - sx, dy = ty = sy;

  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
  cout << endl;
}

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  const int dx = tx - sx, dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
  cout << endl;
}
Problem p03836 (C++)

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

using namespace std;

int sx, sy, tx, ty, dx, dy;
char buf[10005];

void append(char c, int cnt) {
  static int pos = 0;
  for (; cnt; cnt--, pos++) {
    buf[pos] = c;
  }
  buf[pos] = 0;
}

int main() {
  cin >> sx >> sy >> tx >> ty;

  dx = tx - sx;
  dy = ty - sy;

  append('U', dy);
  append('R', dx);
  append('D', dy);
  append('L', dx);
  append('L', 1);
  append('U', dy + 1);
  append('R', dx + 1);
  append('D', 1);
  append('R', 1);
  append('D', dy + 1);
  append('L', dx + 1);
  append('U', 1);

  cout << buf << '\n';
}


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

using namespace std;

int sx, sy, tx, ty, dx, dy;
char buf[20005];

void append(char c, int cnt) {
  static int pos = 0;
  for (; cnt; cnt--, pos++) {
    buf[pos] = c;
  }
  buf[pos] = 0;
}

int main() {
  cin >> sx >> sy >> tx >> ty;

  dx = tx - sx;
  dy = ty - sy;

  append('U', dy);
  append('R', dx);
  append('D', dy);
  append('L', dx);
  append('L', 1);
  append('U', dy + 1);
  append('R', dx + 1);
  append('D', 1);
  append('R', 1);
  append('D', dy + 1);
  append('L', dx + 1);
  append('U', 1);

  cout << buf << '\n';
}
Problem p03836 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  int dx = gx - sx, dy = gy - gx;
  cout << string(dx, 'R') << string(dy, 'U');
  cout << string(dx, 'L') << string(dy, 'D');
  cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
  cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R' << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  int dx = gx - sx, dy = gy - sy;
  cout << string(dx, 'R') << string(dy, 'U');
  cout << string(dx, 'L') << string(dy, 'D');
  cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
  cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R' << endl;
  return 0;
}
Problem p03836 (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 ll;
const int inf = 1001001001;

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sx;

  cout << string(dx, 'R') << string(dy, 'U');
  cout << string(dx, 'L') << string(dy, 'D');
  cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
  cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
  cout << endl;
}

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;

  cout << string(dx, 'R') << string(dy, 'U');
  cout << string(dx, 'L') << string(dy, 'D');
  cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
  cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
  cout << endl;
}
Problem p03836 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 4e3 + 10;

const int mod = 1e9 + 7;

// R , L , D , U
string dr = "RLDU";
int dx[]{1, -1, 0, 0};
int dy[]{0, 0, -1, 1};

int sx, sy;
int tx, ty;
string ans = "";
bool vis[N][N];
bool act[N][N];
pair<int, int> from[N][N];
char is[N][N];

void bfs(int a, int b, int c, int d) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      from[i][j] = {0, 0};
    }
  bool reach;
  memset(vis, 0, sizeof vis);
  queue<pair<int, int>> q;
  q.push({a, b});
  while (q.size()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (x == c && y == d) {
      break;
    }
    vis[x][y] = 1;
    for (int d = 0; d < 4; d++) {
      int X = dx[d] + x;
      int Y = dy[d] + y;
      if (X >= 0 && Y >= 0 && X < N && Y < N && !vis[X][Y] && !act[X][Y]) {
        from[X][Y].first = x;
        from[X][Y].second = y;
        is[X][Y] = dr[d];
        vis[X][Y] = 1;
        q.push({X, Y});
      }
    }
  }
  string cur;
  int X = c, Y = d;
  while (abs(X - a) + abs(Y - b) != 0) {
    cur = is[X][Y] + cur;
    act[X][Y] = 1;
    pair<int, int> p = from[X][Y];
    X = p.first;
    Y = p.second;
  }
  act[a][b] = 0;
  act[c][d] = 0;
  ans += cur;
  // system("PAUSE");
}

int main() {
  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
  sx += 1e3 + 5;
  sy += 1e3 + 5;
  tx += 1e3 + 5;
  ty += 1e3 + 5;
  bfs(sx, sy, tx, ty);
  bfs(tx, ty, sx, sy);
  bfs(sx, sy, tx, ty);
  bfs(tx, ty, sx, sy);
  printf("%s\n", ans.c_str());
  return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 2e3 + 10;

const int mod = 1e9 + 7;

// R , L , D , U
string dr = "RLDU";
int dx[]{1, -1, 0, 0};
int dy[]{0, 0, -1, 1};

int sx, sy;
int tx, ty;
string ans = "";
bool vis[N][N];
bool act[N][N];
pair<int, int> from[N][N];
char is[N][N];

void bfs(int a, int b, int c, int d) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      from[i][j] = {0, 0};
    }
  bool reach;
  memset(vis, 0, sizeof vis);
  queue<pair<int, int>> q;
  q.push({a, b});
  while (q.size()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (x == c && y == d) {
      break;
    }
    vis[x][y] = 1;
    for (int d = 0; d < 4; d++) {
      int X = dx[d] + x;
      int Y = dy[d] + y;
      if (X >= 0 && Y >= 0 && X < N && Y < N && !vis[X][Y] && !act[X][Y]) {
        from[X][Y].first = x;
        from[X][Y].second = y;
        is[X][Y] = dr[d];
        vis[X][Y] = 1;
        q.push({X, Y});
      }
    }
  }
  string cur;
  int X = c, Y = d;
  while (abs(X - a) + abs(Y - b) != 0) {
    cur = is[X][Y] + cur;
    act[X][Y] = 1;
    pair<int, int> p = from[X][Y];
    X = p.first;
    Y = p.second;
  }
  act[a][b] = 0;
  act[c][d] = 0;
  ans += cur;
  // system("PAUSE");
}

int main() {
  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
  sx += 1e3 + 5;
  sy += 1e3 + 5;
  tx += 1e3 + 5;
  ty += 1e3 + 5;
  bfs(sx, sy, tx, ty);
  bfs(tx, ty, sx, sy);
  bfs(sx, sy, tx, ty);
  bfs(tx, ty, sx, sy);
  printf("%s\n", ans.c_str());
  return 0;
}
Problem p03836 (C++)

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

#define pout(n) printf("%d\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int sx, sy, tx, ty;
int main() {
  cin >> sx >> sy >> tx >> ty;
  int w, h;
  w = tx - sx;
  h = ty - sy;

  string ans;

  cout << string(tx, 'R') << string(ty, 'U');
  cout << string(tx, 'L') << string(ty, 'D');
  cout << 'D' << string(tx + 1, 'R') << string(ty + 1, 'U') << 'L';
  cout << 'U' << string(tx + 1, 'L') << string(ty + 1, 'R') << 'D' << endl;
  return 0;
}

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

#define pout(n) printf("%d\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int sx, sy, tx, ty;
int main() {
  cin >> sx >> sy >> tx >> ty;
  int w, h;
  w = tx - sx;
  h = ty - sy;

  string ans;

  cout << string(h, 'U') << string(w, 'R');
  cout << string(h, 'D') << string(w, 'L');
  cout << 'L' << string(h + 1, 'U') << string(w + 1, 'R') << 'D';
  cout << 'R' << string(h + 1, 'D') << string(w + 1, 'L') << 'U' << endl;
  return 0;
}
Problem p03836 (C++)

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

signed main() {
  llin(sx);
  llin(sy);
  llin(lx);
  llin(ly);
  str r(lx - sx, 'R');
  str u(ly - sx, 'U');
  str l(lx - sx, 'L');
  str d(ly - sy, 'D');
  sal(r + u + l + d + "DR" + r + u + "ULUL" + l + d + "DR")
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

signed main() {
  llin(sx);
  llin(sy);
  llin(lx);
  llin(ly);
  str r(lx - sx, 'R');
  str u(ly - sy, 'U');
  str l(lx - sx, 'L');
  str d(ly - sy, 'D');
  sal(r + u + l + d + "DR" + r + u + "ULUL" + l + d + "DR")
}
Problem p03836 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int sx, sy, tx, ty;
  while (scanf("%d%d%d%d", &sx, &sy, &tx, &ty)) {
    printf("L");
    for (int i = 0; i < ty - sy + 1; i++) {
      printf("U");
    }
    for (int i = 0; i < tx - sx + 1; i++) {
      printf("R");
    }
    printf("DR");
    for (int i = 0; i < ty - sy + 1; i++) {
      printf("D");
    }
    for (int i = 0; i < tx - sx + 1; i++) {
      printf("L");
    }
    printf("U");
    for (int i = 0; i < ty - sy; i++) {
      printf("U");
    }
    for (int i = 0; i < tx - sx; i++) {
      printf("R");
    }
    for (int i = 0; i < ty - sy; i++) {
      printf("D");
    }
    for (int i = 0; i < tx - sx; i++) {
      printf("L");
    }
    printf("\n");
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int sx, sy, tx, ty;
  while (~scanf("%d%d%d%d", &sx, &sy, &tx, &ty)) {
    printf("L");
    for (int i = 0; i < ty - sy + 1; i++) {
      printf("U");
    }
    for (int i = 0; i < tx - sx + 1; i++) {
      printf("R");
    }
    printf("DR");
    for (int i = 0; i < ty - sy + 1; i++) {
      printf("D");
    }
    for (int i = 0; i < tx - sx + 1; i++) {
      printf("L");
    }
    printf("U");
    for (int i = 0; i < ty - sy; i++) {
      printf("U");
    }
    for (int i = 0; i < tx - sx; i++) {
      printf("R");
    }
    for (int i = 0; i < ty - sy; i++) {
      printf("D");
    }
    for (int i = 0; i < tx - sx; i++) {
      printf("L");
    }
    printf("\n");
  }
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
#define MAX 100000007
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll ans = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  int a[100] = {0}, b[100] = {0}, c[100] = {0};
  int dist[1000][1000];
  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 < 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 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 == true) {
      ans = ans - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
#define MAX 100000007
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll ans = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  int a[1000] = {0}, b[1000] = {0}, c[1000] = {0};
  int dist[100][100];
  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 < 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 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 == true) {
      ans = ans - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (C++)

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

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

using namespace std;

const int INF = 1 << 29;

int main() {
  int n, m, a[100], b[100], c[100];
  scanf("%d%d", &n, &m);
  rep(i, m) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;

  int d[100][100];
  rep(u, n) rep(v, n) d[u][v] = d[v][u] = (u == v ? 0 : INF);
  rep(i, m) d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];

  rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  int ans = 0;
  rep(i, m) if (c[i] > d[a[i]][b[i]]) ans++;
  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>

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

using namespace std;

const int INF = 1 << 29;

int main() {
  int n, m, a[1000], b[1000], c[1000];
  scanf("%d%d", &n, &m);
  rep(i, m) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;

  int d[100][100];
  rep(u, n) rep(v, n) d[u][v] = d[v][u] = (u == v ? 0 : INF);
  rep(i, m) d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];

  rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  int ans = 0;
  rep(i, m) if (c[i] > d[a[i]][b[i]]) ans++;
  printf("%d\n", ans);

  return 0;
}
Problem p03837 (C++)

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))

using ll = long long;
using P = std::tuple<int, int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
          dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
int d[300][300];
int as[200], bs[200], cs[200];

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

  std::cin >> N >> M;

  fill(&d[0][0], &d[0][0] + 300 * 300, 1001001001);

  for (int i = 0; i < N; ++i) {
    d[i][i] = 0;
  }

  for (int i = 0; i < M; ++i) {
    std::cin >> as[i] >> bs[i] >> cs[i];
    --as[i];
    --bs[i];

    d[as[i]][bs[i]] = min(d[as[i]][bs[i]], cs[i]);
    d[bs[i]][as[i]] = min(d[bs[i]][as[i]], cs[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 res = 0;
  for (int i = 0; i < M; ++i) {
    bool canUse = false;
    for (int j = 0; j < N; ++j) {
      for (int k = j + 1; k < N; ++k) {
        if (d[j][k] == d[j][as[i]] + cs[i] + d[bs[i]][k] ||
            d[j][k] == d[j][bs[i]] + cs[i] + d[as[i]][k]) {
          canUse = true;
        }
      }
    }

    if (!canUse) {
      ++res;
    }
  }

  std::cout << res << std::endl;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))

using ll = long long;
using P = std::tuple<int, int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
          dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
int d[300][300];
int as[1500], bs[1500], cs[1500];

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

  std::cin >> N >> M;

  fill(&d[0][0], &d[0][0] + 300 * 300, 1001001001);

  for (int i = 0; i < N; ++i) {
    d[i][i] = 0;
  }

  for (int i = 0; i < M; ++i) {
    std::cin >> as[i] >> bs[i] >> cs[i];
    --as[i];
    --bs[i];

    d[as[i]][bs[i]] = min(d[as[i]][bs[i]], cs[i]);
    d[bs[i]][as[i]] = min(d[bs[i]][as[i]], cs[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 res = 0;
  for (int i = 0; i < M; ++i) {
    bool canUse = false;
    for (int j = 0; j < N; ++j) {
      for (int k = j + 1; k < N; ++k) {
        if (d[j][k] == d[j][as[i]] + cs[i] + d[bs[i]][k] ||
            d[j][k] == d[j][bs[i]] + cs[i] + d[as[i]][k]) {
          canUse = true;
        }
      }
    }

    if (!canUse) {
      ++res;
    }
  }

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1e9 + 7;

using namespace std;

#define MAX_V 100
struct edge {
  int to, cost;
};
struct inp {
  int a, b, c;
};
typedef pair<int, int> P;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int e;
  bool used[MAX_V];

  scanf("%d%d", &V, &e);
  vector<inp> iedge(e);
  REP(i, e) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    edge e1 = {b, c}, e2 = {a, c};
    G[a].push_back(e1);
    G[b].push_back(e2);
    inp e3 = {a, b, c};
    iedge[i] = e3;
  }
  REP(i, e) used[i] = false;

  REP(i, V) {
    dijkstra(i);
    REP(j, e) {
      if (used[j])
        continue;
      if (d[iedge[j].a] + iedge[j].c == d[iedge[j].b])
        used[j] = true;
    }
  }

  int ans = 0;
  REP(i, e) if (!used[i])++ ans;
  printf("%d\n", ans);
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1e9 + 7;

using namespace std;

#define MAX_V 100
struct edge {
  int to, cost;
};
struct inp {
  int a, b, c;
};
typedef pair<int, int> P;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int e;
  bool used[1000];

  scanf("%d%d", &V, &e);
  vector<inp> iedge(e);
  REP(i, e) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    edge e1 = {b, c}, e2 = {a, c};
    G[a].push_back(e1);
    G[b].push_back(e2);
    inp e3 = {a, b, c};
    iedge[i] = e3;
  }
  REP(i, e) used[i] = false;

  REP(i, V) {
    dijkstra(i);
    REP(j, e) {
      if (used[j])
        continue;
      if (d[iedge[j].a] + iedge[j].c == d[iedge[j].b])
        used[j] = true;
    }
  }

  int ans = 0;
  REP(i, e) if (!used[i])++ ans;
  printf("%d\n", ans);
  return 0;
}
Problem p03837 (C++)

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

// Inserted snippets: io, root
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename H> bool chmin(H &v1, const H v2) {
  if (v1 > v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> bool chmax(H &v1, const H v2) {
  if (v1 < v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> void read(H &head) { cin >> head; }
template <typename H, typename... T> void read(H &head, T &...tail) {
  cin >> head;
  read(tail...);
}
template <typename H> void write(H head) { cout << head << '\n'; }
template <typename H, typename... T> void write(H head, T... tail) {
  cout << head << " ";
  write(tail...);
}
template <typename... T> void die(T... tok) {
  write(tok...);
  exit(0);
}
// End snippets

int dist[105][105];
int a[105], b[105], c[105];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m;
  read(n, m);

  rep(i, 0, n) rep(j, 0, n) dist[i][j] = i == j ? 0 : 0x3f3f3f3f;
  rep(i, 0, m) {
    read(a[i], b[i], c[i]);
    --a[i], --b[i];
    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]);
  int g = 0;
  rep(i, 0, m) if (c[i] > dist[a[i]][b[i]]) g++;
  write(g);
}


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

// Inserted snippets: io, root
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename H> bool chmin(H &v1, const H v2) {
  if (v1 > v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> bool chmax(H &v1, const H v2) {
  if (v1 < v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H> void read(H &head) { cin >> head; }
template <typename H, typename... T> void read(H &head, T &...tail) {
  cin >> head;
  read(tail...);
}
template <typename H> void write(H head) { cout << head << '\n'; }
template <typename H, typename... T> void write(H head, T... tail) {
  cout << head << " ";
  write(tail...);
}
template <typename... T> void die(T... tok) {
  write(tok...);
  exit(0);
}
// End snippets

int dist[105][105];
int a[1005], b[1005], c[1005];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m;
  read(n, m);

  rep(i, 0, n) rep(j, 0, n) dist[i][j] = i == j ? 0 : 0x3f3f3f3f;
  rep(i, 0, m) {
    read(a[i], b[i], c[i]);
    --a[i], --b[i];
    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]);
  int g = 0;
  rep(i, 0, m) if (c[i] > dist[a[i]][b[i]]) g++;
  write(g);
}
Problem p03837 (C++)

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

int main() {
  using std::vector;
  constexpr int inf = 1e9;
  int n, m;
  std::cin >> n >> m;
  vector<vector<int>> d(n, vector<int>(n, inf));
  for (int i = 0; i < n; i++) {
    d.at(i).at(i) = 0;
  }
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < m; i++) {
    std::cin >> a.at(i) >> b.at(i) >> c.at(i);
    a.at(i)--;
    b.at(i)--;
    d.at(a.at(i)).at(b.at(i)) = c.at(i);
    d.at(b.at(i)).at(a.at(i)) = c.at(i);
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d.at(i).at(j) = std::min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (d.at(a.at(i)).at(b.at(i)) < c.at(i)) {
      ans++;
    }
  }
  std::cout << ans << std::endl;
}


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

int main() {
  using std::vector;
  constexpr int inf = 1e9;
  int n, m;
  std::cin >> n >> m;
  vector<vector<int>> d(n, vector<int>(n, inf));
  for (int i = 0; i < n; i++) {
    d.at(i).at(i) = 0;
  }
  vector<int> a(m), b(m), c(m);
  for (int i = 0; i < m; i++) {
    std::cin >> a.at(i) >> b.at(i) >> c.at(i);
    a.at(i)--;
    b.at(i)--;
    d.at(a.at(i)).at(b.at(i)) = c.at(i);
    d.at(b.at(i)).at(a.at(i)) = c.at(i);
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d.at(i).at(j) = std::min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (d.at(a.at(i)).at(b.at(i)) < c.at(i)) {
      ans++;
    }
  }
  std::cout << ans << std::endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (a)-1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define inf (1e9);
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll t = 1;
  rep1(i, n) t *= i;
  return t;
}

ll combinations(ll n, ll k) {
  ll r = 1;
  rep1(i, k) r = r * n-- / i;
  return r;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m), c(m);
  ll g[n][n];
  rep0(i, n) rep0(j, n) {
    if (i == j)
      g[i][j] = 0;
    else
      g[i][j] = inf;
  }

  rep0(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    g[a[i]][b[i]] = min(g[a[i]][b[i]], c[i]);
    g[b[i]][a[i]] = min(g[b[i]][a[i]], c[i]);
  }

  rep0(k, n) rep0(i, n) rep0(j, n) if (g[i][k] + g[k][j] < g[i][j]) g[i][j] =
      g[i][k] + g[k][j];
  ll ans = m;
  rep0(i, m) {
    bool f = false;
    rep0(j, m) if (g[j][a[i]] + c[i] == g[j][b[i]]) f = true;
    if (f)
      --ans;
  }
  pf(ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (a)-1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define inf (1e9);
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll t = 1;
  rep1(i, n) t *= i;
  return t;
}

ll combinations(ll n, ll k) {
  ll r = 1;
  rep1(i, k) r = r * n-- / i;
  return r;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m), c(m);
  ll g[n][n];
  rep0(i, n) rep0(j, n) {
    if (i == j)
      g[i][j] = 0;
    else
      g[i][j] = inf;
  }

  rep0(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    g[a[i]][b[i]] = min(g[a[i]][b[i]], c[i]);
    g[b[i]][a[i]] = min(g[b[i]][a[i]], c[i]);
  }

  rep0(k, n) rep0(i, n) rep0(j, n) if (g[i][k] + g[k][j] < g[i][j]) g[i][j] =
      g[i][k] + g[k][j];
  ll ans = m;
  rep0(i, m) {
    bool f = false;
    rep0(j, n) if (g[j][a[i]] + c[i] == g[j][b[i]]) f = true;
    if (f)
      --ans;
  }
  pf(ans);
  return 0;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int a[N], b[N], c[N];
  int d[N][N];
  REP(i, N) REP(j, N) {
    if (i == j) {
      d[i][j] = 0;
    } else {
      d[i][j] = INF;
    }
  }
  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(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  ll ans = M;
  REP(p, M) {
    bool hasPath = false;
    REP(s, N) {
      if (d[s][a[p]] + c[p] == d[s][b[p]]) {
        hasPath = true;
      }
    }
    if (hasPath) {
      ans--;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int a[M], b[M], c[M];
  int d[N][N];
  REP(i, N) REP(j, N) {
    if (i == j) {
      d[i][j] = 0;
    } else {
      d[i][j] = INF;
    }
  }
  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(k, N) REP(i, N) REP(j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  ll ans = M;
  REP(p, M) {
    bool hasPath = false;
    REP(s, N) {
      if (d[s][a[p]] + c[p] == d[s][b[p]]) {
        hasPath = true;
      }
    }
    if (hasPath) {
      ans--;
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int i = (m); (i) < (n); (i)++)
typedef long long ll;
const int inf = 1e9;

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

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

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int i = (m); (i) < (n); (i)++)
typedef long long ll;
const int inf = 1e9;

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

  vector<vector<int>> dist(n, vector<int>(n, inf));
  rep(i, n) dist[i][i] = 0;
  rep(i, m) {
    dist[a[i]][b[i]] = c[i];
    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 is_shortest = false;
    rep(j, n) {
      if (c[i] + dist[b[i]][j] == dist[a[i]][j])
        is_shortest = true;
    }
    if (is_shortest)
      ans--;
  }
  cout << ans << endl;
  return 0;
}
Problem p03837 (Python)

Buggy submission (status: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N, M = map(int, input().split())
    S = []

    d = [[float("inf")] * N for _ in range(N)]
    L = []
    for i in range(M):
        a, b, c = map(int, input().split())
        d[a - 1][b - 1] = c
        d[b - 1][a - 1] = c
        if a < b:
            L.append((a - 1, b - 1))
        else:
            L.append(b - 1, a - 1)
    for i in range(N):
        d[i][i] = 0
    L = set(L)

    def warshall_floyd(d):
        # d[i][j]: iからjへの最短距離
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    if d[i][j] > d[i][k] + d[k][j]:
                        d[i][j] = d[i][k] + d[k][j]
                        if i < j:
                            if (i, j) in L:
                                S.append((i, j))
                        else:
                            if (j, i) in L:
                                S.append((j, i))
        return d

    warshall_floyd(d)
    print(len(set(S)))


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N, M = map(int, input().split())
    S = []

    d = [[float("inf")] * N for _ in range(N)]
    L = []
    for i in range(M):
        a, b, c = map(int, input().split())
        d[a - 1][b - 1] = c
        d[b - 1][a - 1] = c
        if a < b:
            L.append((a - 1, b - 1))
        else:
            L.append((b - 1, a - 1))
    for i in range(N):
        d[i][i] = 0
    L = set(L)

    def warshall_floyd(d):
        # d[i][j]: iからjへの最短距離
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    if d[i][j] > d[i][k] + d[k][j]:
                        d[i][j] = d[i][k] + d[k][j]
                        if i < j:
                            if (i, j) in L:
                                S.append((i, j))
                        else:
                            if (j, i) in L:
                                S.append((j, i))
        return d

    warshall_floyd(d)
    print(len(set(S)))


if __name__ == "__main__":
    main()
Problem p03837 (C++)

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

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = 1e18 + 1;
ll MOD = 1e9 + 7;

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


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

using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = 1e18 + 1;
ll MOD = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  int d[100][100] = {0};
  for (int i(0); i < 100; i++) {
    for (int j(0); j < 100; j++) {
      if (i == j)
        continue;
      d[i][j] = INFint;
    }
  }
  int a[10000], b[10000], c[10000];
  for (int i(0); i < M; i++) {
    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];
  }
  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(0);
  for (int i(0); i < M; i++) {
    if (d[a[i]][b[i]] != c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 28;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  int n, m, a, b, c;
  cin >> n >> m;
  int dist[n][n], edges[n][n];
  fill_n(dist[0], n * n * n, INF);
  fill_n(edges[0], n * n, INF);
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    dist[a][b] = min(dist[a][b], c);
    dist[b][a] = min(dist[b][a], c);
    edges[a][b] = c;
  }

  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 = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (edges[i][j] == INF)
        continue;
      if (edges[i][j] > dist[i][j])
        ++ans;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 28;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  int n, m, a, b, c;
  cin >> n >> m;
  int dist[n][n], edges[n][n];
  fill_n(dist[0], n * n, INF);
  fill_n(edges[0], n * n, INF);
  for (int i = 1; i <= m; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    dist[a][b] = min(dist[a][b], c);
    dist[b][a] = min(dist[b][a], c);
    edges[a][b] = c;
  }

  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 = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (edges[i][j] == INF)
        continue;
      if (edges[i][j] > dist[i][j])
        ++ans;
    }
  }

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

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

ll n, m;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

int main() {
  cin >> n >> m;
  Graph G(n);
  ll a[m];
  ll b[m];
  ll c[m];
  ll dist[n][n];
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = 1e9;
    }
  }
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(Edge(b[i], c[i]));
    G[b[i]].push_back(Edge(a[i], c[i]));
    dist[a[i]][b[i]] = c[i];
    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]);
      }
    }
  }
  vector<ll> flag(m, 0);
  for (ll i = 0; i < m; i++) {
    for (ll j = 0; j < n; j++) {
      for (ll k = 0; k < n; k++) {
        if (j != k) {
          if (dist[i][j] == dist[i][a[i]] + c[i] + dist[b[i]][j])
            flag[i] = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < m; i++)
    if (flag[i] == 0)
      ans++;
  cout << ans << endl;
}


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

ll n, m;
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

int main() {
  cin >> n >> m;
  Graph G(n);
  ll a[m];
  ll b[m];
  ll c[m];
  ll dist[n][n];
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = 1e9;
    }
  }
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(Edge(b[i], c[i]));
    G[b[i]].push_back(Edge(a[i], c[i]));
    dist[a[i]][b[i]] = c[i];
    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]);
      }
    }
  }
  vector<ll> flag(m, 0);
  for (ll i = 0; i < m; i++) {
    for (ll j = 0; j < n; j++) {
      for (ll k = 0; k < n; k++) {
        if (j != k) {
          if (dist[j][k] == dist[j][a[i]] + c[i] + dist[b[i]][k])
            flag[i] = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < m; i++)
    if (flag[i] == 0)
      ans++;
  cout << ans << endl;
}
Problem p03837 (C++)

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

using namespace std;

const int MAX_V = 1000;
const int INF = 1e9;

int dist[MAX_V][MAX_V];
int n, m;

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

int main() {

  cin >> n >> m;

  int a[n];
  int b[n];
  int c[n];

  // init
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i)
        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];
  }

  warshall_floyd(n);

  int ans = 0;

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

  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int MAX_V = 1000;
const int INF = 1e9;

int dist[MAX_V][MAX_V];
int n, m;

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

int main() {

  cin >> n >> m;

  int a[10000];
  int b[10000];
  int c[10000];

  // init
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i)
        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];
  }

  warshall_floyd(n);

  int ans = 0;

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

  cout << ans << endl;

  return 0;
}