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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

vector<pll> g[51];
ll dist[51][5001];
const ll INF = 1000100010001000100;
int n, m, s;
const int x = 100, y = 5000;
ll C[51], D[51];
void dijkstra(int st) {
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  memset(dist, 0x3f, sizeof(dist));
  dist[st][s] = 0;
  pq.push({dist[st][s] * y + s, st});
  while (!pq.empty()) {
    pll pi = pq.top();
    pq.pop();
    int t = pi.second;
    ll cost = pi.first / y, coin = pi.first % y;
    if (dist[t][coin] < cost)
      continue;

    ll nxb, nxa, nxv, nxco;
    for (auto it : g[t]) {
      nxb = it.first / x, nxa = it.first % x, nxv = it.second;
      if (coin >= nxa && dist[nxv][coin - nxa] > cost + nxb) {
        nxco = coin - nxa;
        dist[nxv][nxco] = (cost + nxb);
        pq.push({dist[nxv][nxco] * y + nxco, nxv});
      }
    }
    nxco = coin + C[t];
    nxco = min(4999ll, nxco);
    if (dist[t][nxco] > cost + D[t]) {
      dist[t][nxco] = cost + D[t];
      pq.push({dist[t][nxco] * y + nxco, t});
    }
  }
}
int main() {
  cin >> n >> m >> s;
  s = min(4999, s);
  ll ui, vi, ai, bi;
  rep(i, m) {
    cin >> ui >> vi >> ai >> bi;
    --ui, --vi;
    g[ui].pb(bi * x + ai, vi);
    g[vi].pb(bi * x + ai, ui);
  }
  rep(i, n) { cin >> C[i] >> D[i]; }
  dijkstra(0);
  FOR(i, 1, n) {
    ll mn = INF;
    rep(j, 5000) mn = min(mn, dist[i][j]);
    cout << mn << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

vector<pll> g[51];
ll dist[51][5001];
const ll INF = 1000100010001000100;
int n, m, s;
const int x = 100, y = 5000;
ll C[51], D[51];
int dijkstra(int st) {
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  memset(dist, 0x3f, sizeof(dist));
  dist[st][s] = 0;
  pq.push({dist[st][s] * y + s, st});
  while (!pq.empty()) {
    pll pi = pq.top();
    pq.pop();
    int t = pi.second;
    ll cost = pi.first / y, coin = pi.first % y;
    if (dist[t][coin] < cost)
      continue;

    ll nxb, nxa, nxv, nxco;
    for (auto it : g[t]) {
      nxb = it.first / x, nxa = it.first % x, nxv = it.second;
      if (coin >= nxa && dist[nxv][coin - nxa] > cost + nxb) {
        nxco = coin - nxa;
        dist[nxv][nxco] = (cost + nxb);
        pq.push({dist[nxv][nxco] * y + nxco, nxv});
      }
    }
    nxco = coin + C[t];
    nxco = min(4999ll, nxco);
    if (dist[t][nxco] > cost + D[t]) {
      dist[t][nxco] = cost + D[t];
      pq.push({dist[t][nxco] * y + nxco, t});
    }
  }
}
int main() {
  cin >> n >> m >> s;
  s = min(4999, s);
  ll ui, vi, ai, bi;
  rep(i, m) {
    cin >> ui >> vi >> ai >> bi;
    --ui, --vi;
    g[ui].pb(bi * x + ai, vi);
    g[vi].pb(bi * x + ai, ui);
  }
  rep(i, n) { cin >> C[i] >> D[i]; }
  dijkstra(0);
  FOR(i, 1, n) {
    ll mn = INF;
    rep(j, 5000) mn = min(mn, dist[i][j]);
    cout << mn << endl;
  }
  return 0;
}