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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

struct edge {
  int to, sil;
  ll cost;
};

struct node {
  int n, sil;
  ll cost;
  bool operator<(const node &n) const { return cost < n.cost; }

  bool operator>(const node &n) const { return cost > n.cost; }
};

int N, M, S;
ll d[60][6000];
vector<edge> G[60];
ll C[60], D[60];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    int U, V, A, B;
    cin >> U >> V >> A >> B;
    G[U].push_back(edge{V, A, B});
    G[V].push_back(edge{U, A, B});
  }
  for (int i = 1; i <= N; i++) {
    cin >> C[i] >> D[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 5010; j++) {
      d[i][j] = linf;
    }
  }
  priority_queue<node, vector<node>, greater<node>> pq;
  pq.push(node{1, S, 0});
  d[1][min(S, 5001)] = 0;
  while (!pq.empty()) {
    node n = pq.top();
    pq.pop();
    if (d[n.n][min(n.sil, 5001)] < n.cost)
      continue;
    int s = n.sil;
    if (s <= 5000) {
      s += C[n.n];
      ll t = n.cost + D[n.n];
      chmin(s, 5001);
      if (d[n.n][s] > t) {
        d[n.n][s] = t;
        pq.push(node{n.n, s, t});
      }
    }
    for (auto u : G[n.n]) {
      int si = n.sil - u.sil;
      ll co = n.cost + u.cost;
      if (si >= 0 && d[u.to][min(si, 5001)] > co) {
        d[u.to][min(si, 5001)] = co;
        pq.push(node{u.to, si, co});
      }
    }
  }
  for (int i = 2; i <= N; i++) {
    ll ans = linf;
    for (int j = 0; j <= 5001; j++) {
      chmin(ans, d[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template <class T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}
template <class T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}

struct edge {
  int to, sil;
  ll cost;
};

struct node {
  int n, sil;
  ll cost;
  bool operator<(const node &n) const { return cost < n.cost; }

  bool operator>(const node &n) const { return cost > n.cost; }
};

int N, M, S;
ll d[50][6000];
vector<edge> G[60];
ll C[60], D[60];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    int U, V, A, B;
    cin >> U >> V >> A >> B;
    G[U].push_back(edge{V, A, B});
    G[V].push_back(edge{U, A, B});
  }
  for (int i = 1; i <= N; i++) {
    cin >> C[i] >> D[i];
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 5010; j++) {
      d[i][j] = linf;
    }
  }
  priority_queue<node, vector<node>, greater<node>> pq;
  pq.push(node{1, S, 0});
  d[1][min(S, 5001)] = 0;
  while (!pq.empty()) {
    node n = pq.top();
    pq.pop();
    if (d[n.n][min(n.sil, 5001)] < n.cost)
      continue;
    int s = n.sil;
    if (s <= 5000) {
      s += C[n.n];
      ll t = n.cost + D[n.n];
      chmin(s, 5001);
      if (d[n.n][s] > t) {
        d[n.n][s] = t;
        pq.push(node{n.n, s, t});
      }
    }
    for (auto u : G[n.n]) {
      int si = n.sil - u.sil;
      int co = n.cost + u.cost;
      if (si >= 0 && d[u.to][min(si, 5001)] > co) {
        d[u.to][min(si, 5001)] = co;
        pq.push(node{u.to, si, co});
      }
    }
  }
  for (int i = 2; i <= N; i++) {
    ll ans = linf;
    for (int j = 0; j <= 5001; j++) {
      chmin(ans, d[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}