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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int mod = 1e9 + 7;
const int cmax = 2500;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  chmin(s, cmax);
  vector<vector<pair<int, int>>> g(n);
  vector<ll> a(m), b(m);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    cin >> a[i] >> b[i];
    u--, v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  vector<ll> c(n), d(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
  }
  vector<vector<ll>> dp(n, vector<ll>(cmax + 1, INF));
  priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>,
                 greater<pair<ll, pair<ll, ll>>>>
      pq;
  dp[0][s] = 0;
  pq.push({0, {0, s}});
  while (!pq.empty()) {
    ll u = pq.top().first, v = pq.top().second.first,
       w = pq.top().second.second;
    pq.pop();
    if (u > dp[v][w]) {
      continue;
    }
    if (w + c[v] <= cmax) {
      if (chmin(dp[v][w + c[v]], u + d[v])) {
        pq.push({u + d[v], {v, w + c[v]}});
      }
    }
    for (auto x : g[v]) {
      int to = x.first;
      ll A = a[x.second], B = b[x.second];
      if (w < A) {
        continue;
      }
      if (chmin(dp[to][w - A], dp[v][w] + B)) {
        pq.push({dp[to][w - A], {to, w - A}});
      }
    }
  }
  for (int i = 1; i < n; i++) {
    ll ans = INF;
    for (int j = 0; j <= cmax; j++) {
      chmin(ans, dp[i][j]);
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int mod = 1e9 + 7;
const int cmax = 2500;
typedef pair<ll, pair<ll, ll>> PLPLL;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  chmin(s, cmax);
  vector<vector<pair<int, int>>> g(n);
  vector<ll> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    cin >> a[i] >> b[i];
    u--, v--;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  vector<ll> c(n), d(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
  }
  vector<vector<ll>> dp(n, vector<ll>(cmax + 1, INF));
  priority_queue<PLPLL, vector<PLPLL>, greater<PLPLL>> pq;
  dp[0][s] = 0;
  pq.push({0, {0, s}});
  while (!pq.empty()) {
    ll u = pq.top().first, v = pq.top().second.first,
       w = pq.top().second.second;
    pq.pop();
    if (u > dp[v][w]) {
      continue;
    }
    if (w + c[v] <= cmax) {
      if (chmin(dp[v][w + c[v]], u + d[v])) {
        pq.push({u + d[v], {v, w + c[v]}});
      }
    }
    for (auto x : g[v]) {
      int to = x.first;
      ll A = a[x.second], B = b[x.second];
      if (w < A) {
        continue;
      }
      if (chmin(dp[to][w - A], dp[v][w] + B)) {
        pq.push({dp[to][w - A], {to, w - A}});
      }
    }
  }
  for (int i = 1; i < n; i++) {
    ll ans = INF;
    for (int j = 0; j <= cmax; j++) {
      chmin(ans, dp[i][j]);
    }
    cout << ans << endl;
  }
}