Problem p02361 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <vector>

#define INF 999999999
#define ll long long

using namespace std;

const int MAX_N = 100000;
const int MAX_M = 500000;

struct edge {
  int from; //?????????
  int to;   //??°??????
  int cost; //??????
};

int d[MAX_N];
edge es[MAX_M];
bool flag; //???????????????????????????

void shortest_path(
    int n, int m,
    int s) // s???????????????????????????????????????????????¢????±???????
{
  int cnt = 0;
  fill(d, d + n, INF);
  d[s] = 0;
  while (true && cnt < n) {
    bool update = false;
    for (int i = 0; i < m; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
    cnt++;
  }
  if (cnt == n) {
    flag = true;
  }
}

int main() {
  int i, n, m, s;
  cin >> n; //????????°
  cin >> m; //?????°
  cin >> s; //???????????????
  for (int i = 0; i < m; i++) {
    scanf("%d", &es[i].from);
    scanf("%d", &es[i].to);
    scanf("%d", &es[i].cost);
  }
  flag = false;
  shortest_path(n, m, s);
  if (!flag) {
    for (int i = 0; i < n; i++) {
      if (d[i] == INF) {
        cout << "INF\\n";
      } else {
        cout << d[i] << "\\n";
      }
    }
  } else {
    cout << "NEGATIVE CYCLE\\n";
  }
}


Error: 127
/tmp/3eb982ee-cba1-4b62-8717-5edb5c69aef8.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n)                                                              \\
  cout << #a << ":";                                                           \\
  rep(pachico, n) cout << " " << a[pachico];                                   \\
  cout << endl
#define svec(v)                                                                \\
  cout << #v << ":";                                                           \\
  rep(pachico, v.size()) cout << " " << v[pachico];                            \\
  cout << endl
#define svecp(v)                                                               \\
  cout << #v << ":";                                                           \\
  each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second      \\
                        << "}";                                                \\
  cout << endl
#define sset(s)                                                                \\
  cout << #s << ":";                                                           \\
  each(pachico, s) cout << " " << pachico;                                     \\
  cout << endl
#define smap(m)                                                                \\
  cout << #m << ":";                                                           \\
  each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second      \\
                        << "}";                                                \\
  cout << endl

using namespace std;

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

int G[MAX_N][MAX_N], nx[MAX_N], prv[MAX_N], d[MAX_N];

inline void Dijkstra(int node_size, int s) {
  int V = node_size, mn, mn_id = s, v, j;
  iota(nx, nx + V, 1), iota(prv + 1, prv + V + 1, 0);
  nx[V] = 0, prv[0] = V;
  fill(d, d + V, INF);
  d[s] = 0;
  for (int i = 0; i < V - 1; i++) {
    v = mn_id, mn = INF;
    nx[prv[mn_id]] = nx[mn_id], prv[nx[mn_id]] = prv[mn_id];
    for (j = nx[V]; j != V; j = nx[j]) {
      d[j] = min(d[j], d[v] + G[v][j]);
      if (d[j] < mn)
        mn = d[j], mn_id = j;
    }
    if (mn == INF)
      break;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, n) {
    rep(j, n) { G[i][j] = INF; }
  }
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a][b] = c;
  }
  Dijkstra(n, s);
  rep(i, n) {
    if (d[i] == INF) {
      cout << "INF\\n";
    } else {
      cout << d[i] << "\\n";
    }
  }
  return 0;
}