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

// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve() {
  int n, m, s;
  cin >> n >> m >> s;
  int C = 55 * 55;
  yukari<pair<int, i64>> g(n * C);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    for (int j = 0; j < C - 1; j++) {
      g[n * min(j + a, C - 1) + u].emplace_back(n * j + v, b);
      g[n * min(j + a, C - 1) + v].emplace_back(n * j + u, b);
    }
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j < C - 1; j++) {
      g[n * j + i].emplace_back(n * min(j + c, C - 1) + i, d);
    }
  }
  akari<i64> dp(n * C + 10, 1e15);
  akane<pair<i64, int>> pq;
  s = min(s, 51 * 51);
  dp[n * s] = 0;
  pq.push({0, n * s});
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int v = p.second;
    i64 c = p.first;
    // print(v % n, c);
    for (auto &e : g[v]) {
      int nv = e.first;
      i64 nc = c + e.second;
      if (dp[nv] > nc) {
        dp[nv] = nc;
        pq.push({nc, nv});
      }
    }
  }
  for (int v = 1; v < n; v++) {
    i64 ans = 1e15;
    for (int j = 0; j < C; j++) {
      ans = min(ans, dp[j * n + v]);
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}


Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve() {
  int n, m, s;
  cin >> n >> m >> s;
  int C = 55 * 55;
  yukari<pair<int, i64>> g(n * C);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    for (int j = 0; j < C - a; j++) {
      g[n * (j + a) + u].emplace_back(n * j + v, b);
      g[n * (j + a) + v].emplace_back(n * j + u, b);
    }
  }
  for (int i = 0; i < m; i++) {
    int c, d;
    cin >> c >> d;
    c = min(c, C - 1);
    for (int j = 0; j < C; j++) {
      g[n * j + i].emplace_back(n * min(j + c, C - 1) + i, d);
    }
  }
  akari<i64> dp(n * C + 10, 1e15);
  akane<pair<i64, int>> pq;
  s = min(s, 51 * 51);
  dp[n * s] = 0;
  pq.push({0, n * s});
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int v = p.second;
    i64 c = p.first;
    // print(v % n, c);
    for (auto &e : g[v]) {
      int nv = e.first;
      i64 nc = c + e.second;
      if (dp[nv] > nc) {
        dp[nv] = nc;
        pq.push({nc, nv});
      }
    }
  }
  for (int v = 1; v < n; v++) {
    i64 ans = 1e16;
    for (int j = 0; j < C; j++) {
      ans = min(ans, dp[j * n + v]);
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}