Problem p03837 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston                                                             \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

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

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; // 998244353
const double PI = acos(-1);

long long g[102][102];
set<pair<int, int>> setik;

int dijkstra(int s, int n) {
  vector<int> d(n + 1, INF);
  d[s] = 0;
  vector<bool> used(n + 1);
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    int v = -1;
    for (int j = 1; j <= n; j++) {
      if (!used[j] and (v == -1 or d[j] < d[v])) {
        v = j;
      }
    }
    if (d[v] == INF)
      break;
    used[v] = true;
    for (int to = 1; to <= n; to++) {
      if (g[v][to] == 0)
        continue;
      if (d[v] + g[v][to] < d[to]) {
        d[to] = d[v] + g[v][to];
        p[to] = v;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int j = i;
    if (j == s)
      continue;
    while (p[j] != 0) {
      int mn = min(j, p[j]);
      int mx = max(j, p[j]);
      setik.insert(mp(mn, mx));
      j = p[j];
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a][b] = c;
    g[b][a] = c;
  }
  for (int i = 1; i <= n; i++) {
    dijkstra(i, n);
  }
  cout << m - setik.size() << endl;
}

int main() {
  // freopen("bbreeds.in", "r", stdin);
  // freopen("bbreeds.out", "w", stdout);
  jonathan;
  livingston;
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston                                                             \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

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

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; // 998244353
const double PI = acos(-1);

long long g[102][102];
set<pair<int, int>> setik;

void dijkstra(int s, int n) {
  vector<int> d(n + 1, INF);
  d[s] = 0;
  vector<bool> used(n + 1);
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    int v = -1;
    for (int j = 1; j <= n; j++) {
      if (!used[j] and (v == -1 or d[j] < d[v])) {
        v = j;
      }
    }
    if (d[v] == INF)
      break;
    used[v] = true;
    for (int to = 1; to <= n; to++) {
      if (g[v][to] == 0)
        continue;
      if (d[v] + g[v][to] < d[to]) {
        d[to] = d[v] + g[v][to];
        p[to] = v;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int j = i;
    if (j == s)
      continue;
    while (p[j] != 0) {
      int mn = min(j, p[j]);
      int mx = max(j, p[j]);
      setik.insert(mp(mn, mx));
      j = p[j];
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a][b] = c;
    g[b][a] = c;
  }
  for (int i = 1; i <= n; i++) {
    dijkstra(i, n);
  }
  cout << m - setik.size() << endl;
}

int main() {
  // freopen("bbreeds.in", "r", stdin);
  // freopen("bbreeds.out", "w", stdout);
  jonathan;
  livingston;
  solve();
  return 0;
}