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

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<ll, pair<ll, ll>>;
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep0(i, n) for (int i = 0; i < n; i++)
#define zarray(x, n)                                                           \\
  x[n + 1];                                                                    \\
  rep1(i, n) { x[i] = 0; }

int main() {
  int n, m, s;
  cin >> n >> m >> s;

  int MAX_SILVER = 2500;
  if (s > MAX_SILVER) {
    s = MAX_SILVER;
  }

  map<int, vector<pair<int, pair<int, int>>>> g;
  rep0(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }

  ll C[n + 1];
  ll D[n + 1];
  rep1(i, n) {
    ll c, d;
    cin >> c >> d;
    D[i] = c;
    C[i] = d;
  }

  ll time[n + 1][2501];
  rep1(i, n) {
    rep0(j, 2501) { time[i][j] = INT64_MAX; }
  }
  priority_queue<P, vector<P>, greater<P>> q;
  // cout << "searching.." << endl;

  q.push({0, {1, s}});
  time[1][s] = 0;

  while (!q.empty()) {
    auto a = q.top();
    q.pop();
    ll d = a.first;
    int here = a.second.first;
    ll s = a.second.second;
    if (time[here][s] > d)
      continue;

    // cout << "d:" << d << " here:" << here << " s:" << s << " as:" << D[here]
    // << " ts:" << C[here] << endl;

    ll ns = (s + D[here]);
    if (ns <= MAX_SILVER) {
      ll new_time = d + C[here];
      if (time[here][ns] > new_time) {
        time[here][ns] = new_time;
        q.push({new_time, {here, ns}});
        // cout << "pushed add: " << here << " " << new_time << " " << ns <<
        // endl;
      }
    }

    for (auto edge : g[here]) {
      int to = edge.first;
      ll travel_cost = edge.second.first;
      ll travel_time = edge.second.second;

      ll w = d + travel_time;
      ll ns = s - travel_cost;
      // cout << "to:" << to << " c:" << travel_cost << " time:" << travel_time
      // << " w:" << w << " ss:" << ns << endl;
      if (ns < 0)
        continue;

      if (w < time[to][ns]) {
        time[to][ns] = w;
        q.push({w, {to, ns}});
        // cout << "pushed travel:" << to << " " << w << " " << ns << endl;
      }
    }
  }

  for (int i = 2; i < n + 1; i++) {
    ll min = INT64_MAX;
    rep0(j, MAX_SILVER + 1) {
      // cout << "min:" << min << " j:" << j << " t:" << time[i][j] << endl;
      if (min > time[i][j]) {
        min = time[i][j];
      }
    }
    if (min == INT64_MAX) {
      min = 0;
    }
    cout << min << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<ll, pair<ll, ll>>;
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep0(i, n) for (int i = 0; i < n; i++)
#define zarray(x, n)                                                           \\
  x[n + 1];                                                                    \\
  rep1(i, n) { x[i] = 0; }

int main() {
  int n, m, s;
  cin >> n >> m >> s;

  int MAX_SILVER = m * 50 + 1;
  if (s > MAX_SILVER) {
    s = MAX_SILVER;
  }

  map<int, vector<pair<int, pair<int, int>>>> g;
  rep0(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }

  ll C[n + 1];
  ll D[n + 1];
  rep1(i, n) {
    ll c, d;
    cin >> c >> d;
    D[i] = c;
    C[i] = d;
  }

  ll time[n + 1][2501];
  rep1(i, n) {
    rep0(j, 2501) { time[i][j] = INT64_MAX; }
  }
  priority_queue<P, vector<P>, greater<P>> q;
  // cout << "searching.." << endl;

  q.push({0, {1, s}});
  time[1][s] = 0;

  while (!q.empty()) {
    auto a = q.top();
    q.pop();
    ll d = a.first;
    int here = a.second.first;
    ll s = a.second.second;
    if (time[here][s] > d)
      continue;

    // cout << "d:" << d << " here:" << here << " s:" << s << " as:" << D[here]
    // << " ts:" << C[here] << endl;

    ll ns = (s + D[here]);
    if (ns <= MAX_SILVER) {
      ll new_time = d + C[here];
      if (time[here][ns] > new_time) {
        time[here][ns] = new_time;
        q.push({new_time, {here, ns}});
        // cout << "pushed add: " << here << " " << new_time << " " << ns <<
        // endl;
      }
    }

    for (auto edge : g[here]) {
      int to = edge.first;
      ll travel_cost = edge.second.first;
      ll travel_time = edge.second.second;

      ll w = d + travel_time;
      ll ns = s - travel_cost;
      // cout << "to:" << to << " c:" << travel_cost << " time:" << travel_time
      // << " w:" << w << " ss:" << ns << endl;
      if (ns < 0)
        continue;

      if (w < time[to][ns]) {
        time[to][ns] = w;
        q.push({w, {to, ns}});
        // cout << "pushed travel:" << to << " " << w << " " << ns << endl;
      }
    }
  }

  for (int i = 2; i < n + 1; i++) {
    ll min = INT64_MAX;
    rep0(j, MAX_SILVER + 1) {
      // cout << "min:" << min << " j:" << j << " t:" << time[i][j] << endl;
      if (min > time[i][j]) {
        min = time[i][j];
      }
    }
    if (min == INT64_MAX) {
      min = 0;
    }
    cout << min << endl;
  }
}