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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for (int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, s64>;

vector<vector<P>> g;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, s;
  cin >> n >> m >> s;
  s = MIN(2500, s);

  g.resize(n * 2501);
  int u, v, a, b;
  rep(i, m) {
    cin >> u >> v >> a >> b;
    --u;
    --v;

    for (int j = 2499; j - a >= 0; --j) {
      g[j * n + u].emplace_back((j - a) * n + v, b);
      g[j * n + v].emplace_back((j - a) * n + u, b);
    }
    g[2500 * n + u].emplace_back(2500 * n + v, b);
    g[2500 * n + v].emplace_back(2500 * n + u, b);
  }

  rep(i, n) {
    s64 c, d;
    cin >> c >> d;
    rep(j, 2500) { g[j * n + i].emplace_back(MIN(2500, j + c) * n + i, d); }
  }

  vs64 d(n * 2501, 1e18);
  d[s * n + 0] = 0;
  vector<bool> reached(n * 2501, false);
  priority_queue<P> pq;
  pq.push(P{0, s * n + 0});
  while (!pq.empty()) {
    P du = pq.top();
    pq.pop();
    s64 dist = -du.first;
    int u = du.second;

    if (reached[u])
      continue;
    reached[u] = true;

    for (auto v : g[u]) {
      int to = v.first;
      s64 t = v.second;
      if (d[to] > dist + t) {
        pq.push(P{-(dist + t), to});
        d[to] = dist + t;
      }
    }
  }

  for (int t = 1; t < n; ++t) {
    s64 ans = 1e18;
    rep(i, 2501) ans = MIN(ans, d[n * i + t]);
    cout << ans << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for (int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, s64>;

vector<vector<P>> g;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, s;
  cin >> n >> m >> s;

  g.resize(n * 5001);
  int u, v, a, b;
  rep(i, m) {
    cin >> u >> v >> a >> b;
    --u;
    --v;

    for (int j = 4999; j - a >= 0; --j) {
      g[j * n + u].emplace_back((j - a) * n + v, b);
      g[j * n + v].emplace_back((j - a) * n + u, b);
    }
    g[5000 * n + u].emplace_back(5000 * n + v, b);
    g[5000 * n + v].emplace_back(5000 * n + u, b);
  }

  rep(i, n) {
    s64 c, d;
    cin >> c >> d;
    rep(j, 5000) { g[j * n + i].emplace_back(MIN(5000, j + c) * n + i, d); }
  }

  vs64 d(n * 5001, 1e18);
  d[s * n + 0] = 0;
  vector<bool> reached(n * 5001, false);
  priority_queue<P> pq;
  pq.push(P{0, s * n + 0});
  while (!pq.empty()) {
    P du = pq.top();
    pq.pop();
    int dist = -du.first;
    int u = du.second;

    if (reached[u])
      continue;
    reached[u] = true;

    for (auto v : g[u]) {
      int to = v.first;
      s64 t = v.second;
      if (!reached[to] && d[to] > dist + t) {
        pq.push(P{-(dist + t), to});
        d[to] = dist + t;
      }
    }
  }

  for (int t = 1; t < n; ++t) {
    s64 ans = 1e18;
    rep(i, 5001) ans = MIN(ans, d[n * i + t]);
    cout << ans << "\\n";
  }
  return 0;
}