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

#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \\
  { cerr << "# " << __VA_ARGS__ << "\\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
public:
  int n, m, s;
  struct G {
    i64 v, t, c;
    G(i64 a, i64 b, i64 c) : v(a), t(b), c(c) {}
  };
  vector<G> V[55];
  struct ND {
    i64 tim, u, s;
    ND(i64 a, i64 b, i64 c) : tim(a), u(b), s(c) {}
    bool operator<(const ND &p1) const { return tim > p1.tim; }
  };
  i64 dis[55][5555];
  void solve() {
    cin >> n >> m >> s;
    for (int i = 0; i < m; ++i) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      V[u].emplace_back(v, b, a);
      V[v].emplace_back(u, b, a);
    }
    for (int i = 1; i <= n; ++i) {
      int c, d;
      cin >> c >> d;
      V[i].emplace_back(i, d, -c);
    }
    s = min(s, 5000);
    for (int i = 0; i < 55; ++i)
      for (int j = 0; j < 5555; ++j)
        dis[i][j] = 1e18;
    priority_queue<ND> que;
    dis[1][s] = 0;
    que.emplace(0, 1, s);
    while (que.size()) {
      auto [tim, u, s] = que.top();
      que.pop();
      for (auto [v, t, c] : V[u]) {
        if (s - c < 0 || s - c > 5000)
          continue;
        if (dis[v][s - c] > tim + t) {
          dis[v][s - c] = tim + t;
          que.emplace(tim + t, v, s - c);
        }
      }
    }
    for (int i = 2; i <= n; ++i) {
      i64 ans = 1e18;
      for (int j = 0; j < 5555; ++j)
        ans = min(ans, dis[i][j]);
      cout << ans << "\\n";
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \\
  { cerr << "# " << __VA_ARGS__ << "\\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
public:
  int n, m, s;
  struct G {
    int v, t, c;
    G(int a, int b, int c) : v(a), t(b), c(c) {}
  };
  vector<G> V[55];
  struct ND {
    int tim, u, s;
    ND(int a, int b, int c) : tim(a), u(b), s(c) {}
    bool operator<(const ND &p1) const { return tim > p1.tim; }
  };
  i64 dis[55][5555];
  void solve() {
    cin >> n >> m >> s;
    for (int i = 0; i < m; ++i) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      V[u].emplace_back(v, b, a);
      V[v].emplace_back(u, b, a);
    }
    for (int i = 1; i <= n; ++i) {
      int c, d;
      cin >> c >> d;
      V[i].emplace_back(i, d, -c);
    }
    s = min(s, 5000);
    for (int i = 0; i < 55; ++i)
      for (int j = 0; j < 5555; ++j)
        dis[i][j] = 1e18;
    priority_queue<ND> que;
    dis[1][s] = 0;
    que.emplace(0, 1, s);
    while (que.size()) {
      auto [tim, u, s] = que.top();
      que.pop();
      for (auto [v, t, c] : V[u]) {
        if (s - c < 0)
          continue;
        if (dis[v][s - c] > tim + t) {
          dis[v][s - c] = tim + t;
          que.emplace(tim + t, v, s - c);
        }
      }
    }
    for (int i = 2; i <= n; ++i) {
      i64 ans = 1e18;
      for (int j = 0; j < 5555; ++j)
        ans = min(ans, dis[i][j]);
      cout << ans << "\\n";
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}