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

#include <bits/stdc++.h> // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 26 21:18:52 JST 2020
 **/

template <class T> inline bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

using namespace std;
class UndirectedGraph {
  struct Edge {
    Int to, cost;
  };

public:
  vector<vector<Edge>> G;
  Int V;
  UndirectedGraph(Int V) : G(V), V(V) {}
  void add_edge(Int u, Int v, Int cost) { G[u].push_back({v, cost}); }
  vector<Int> dijkstra(Int s) {
    vector<Int> d(V, 1e18);
    d[s] = 0;
    priority_queue<pair<Int, Int>, vector<pair<Int, Int>>,
                   greater<pair<Int, Int>>>
        que; // {dist, v}
    que.push({0, s});
    while (!que.empty()) {
      pair<Int, Int> p = que.top();
      dump(p);
      que.pop();
      Int v = p.second;
      if (d[v] < p.first)
        continue; // 定数倍枝刈り
      for (Edge e : G[v]) {
        Int tmp = d[v] + e.cost;
        if (d[e.to] <= tmp)
          continue;
        d[e.to] = tmp;
        que.push({tmp, e.to});
      }
    }
    return d;
  }
};

signed main() {
  Int n, m, S;
  std::cin >> n >> m >> S;
  const Int K = 5001;
  auto enc = [&](Int v, Int j) {
    assert(j < K);
    return K * v + j;
  };
  UndirectedGraph g(n * K);
  REP(_, m) {
    Int u, v, a, b;
    std::cin >> u >> v >> a >> b;
    u--, v--;
    REP(j, a, K) {
      g.add_edge(enc(u, j), enc(v, j - a), b);
      g.add_edge(enc(v, j), enc(u, j - a), b);
    }
  }
  REP(i, n) {
    Int c, d;
    std::cin >> c >> d;
    REP(j, K) {
      if (j + c >= K)
        break;
      g.add_edge(enc(i, j), enc(i, j + c), d);
    }
  }
  auto d = g.dijkstra(enc(0, std::min(S, K - 1)));
  dump(d);
  REP(i, 1, n) {
    Int mi = 1e18;
    REP(j, K) chmin(mi, d[enc(i, j)]);
    std::cout << mi << "\\n";
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h> // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 26 21:18:52 JST 2020
 **/

template <class T> inline bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}

using namespace std;
class UndirectedGraph {
  struct Edge {
    Int to, cost;
  };

public:
  vector<vector<Edge>> G;
  Int V;
  UndirectedGraph(Int V) : G(V), V(V) {}
  void add_edge(Int u, Int v, Int cost) { G[u].push_back({v, cost}); }
  vector<Int> dijkstra(Int s) {
    vector<Int> d(V, 1e18);
    d[s] = 0;
    priority_queue<pair<Int, Int>, vector<pair<Int, Int>>,
                   greater<pair<Int, Int>>>
        que; // {dist, v}
    que.push({0, s});
    while (!que.empty()) {
      pair<Int, Int> p = que.top();
      dump(p);
      que.pop();
      Int v = p.second;
      if (d[v] < p.first)
        continue; // 定数倍枝刈り
      for (Edge e : G[v]) {
        Int tmp = d[v] + e.cost;
        if (d[e.to] <= tmp)
          continue;
        d[e.to] = tmp;
        que.push({tmp, e.to});
      }
    }
    return d;
  }
};

signed main() {
  Int n, m, S;
  std::cin >> n >> m >> S;
  const Int K = 5001;
  auto enc = [&](Int v, Int j) {
    assert(j < K);
    return K * v + j;
  };
  UndirectedGraph g(n * K);
  REP(_, m) {
    Int u, v, a, b;
    std::cin >> u >> v >> a >> b;
    u--, v--;
    REP(j, a, K) {
      g.add_edge(enc(u, j), enc(v, j - a), b);
      g.add_edge(enc(v, j), enc(u, j - a), b);
    }
  }
  REP(i, n) {
    Int c, d;
    std::cin >> c >> d;
    REP(j, K) {
      if (j + c >= K)
        break;
      g.add_edge(enc(i, j), enc(i, j + c), d);
    }
  }
  auto d = g.dijkstra(enc(0, S));
  dump(d);
  REP(i, 1, n) {
    Int mi = 1e18;
    REP(j, K) chmin(mi, d[enc(i, j)]);
    std::cout << mi << "\\n";
  }
}