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

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for (auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct edge {
  ll to, maisu, cost;
};
vector<edge> g[50];
vl v_maisu, v_hun;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> a;
  rep(i, m) {
    cin >> x >> y >> z >> w;
    x--;
    y--;
    g[x].push_back({y, z, w});
    g[y].push_back({x, z, w});
  }

  rep(i, n) {
    cin >> x >> y;
    v_maisu.push_back(x);
    v_hun.push_back(y);
  }

  ll dp[50][20000];
  rep(i, 50) {
    rep(j, 20000) { dp[i][j] = INF; }
  }

  t = n - 1;
  priority_queue<pair<ll, PP>, vector<pair<ll, PP>>, greater<pair<ll, PP>>> VP;

  rep(i, min(a, 9999LL) + 1) { dp[0][i] = 0; }
  VP.push(make_pair(0LL, make_pair(min(a, 9999LL), 0)));
  // cout << dp[0][2] << endl;

  e = 200000;
  while (e--) {
    auto C = VP.top();
    x = C.first;         // 今の分
    y = C.second.first;  // 今の枚数
    z = C.second.second; // 今の頂点
    VP.pop();
    if (10000 > y + v_maisu[z] && dp[z][y + v_maisu[z]] > x + v_hun[z]) {
      VP.push(make_pair(x + v_hun[z], make_pair(y + v_maisu[z], z)));
      k = y + v_maisu[z];
      while (dp[z][k] > x + v_hun[z]) {
        dp[z][k] = x + v_hun[z];
        k--;
      }
    }
    for (edge i : g[z]) {
      p = i.cost;
      q = i.to;
      r = i.maisu;
      if (y >= r && dp[q][y - r] > x + p) {
        k = y - r;
        while (dp[q][k] > x + p) {
          dp[q][k] = x + p;
          if (k == 0) {
            // cout << x + p << " " << y - r << " " << q << endl;
            t--;
            break;
          }
          k--;
        }
        VP.push(make_pair(x + p, make_pair(y - r, q)));
      }
    }
  }

  rep(i, n - 1) { cout << dp[i + 1][0] << endl; }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for (auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct edge {
  ll to, maisu, cost;
};
vector<edge> g[50];
vl v_maisu, v_hun;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> a;
  rep(i, m) {
    cin >> x >> y >> z >> w;
    x--;
    y--;
    g[x].push_back({y, z, w});
    g[y].push_back({x, z, w});
  }

  rep(i, n) {
    cin >> x >> y;
    v_maisu.push_back(x);
    v_hun.push_back(y);
  }

  ll dp[50][20000];
  rep(i, 50) {
    rep(j, 20000) { dp[i][j] = INF; }
  }

  t = n - 1;
  priority_queue<pair<ll, PP>, vector<pair<ll, PP>>, greater<pair<ll, PP>>> VP;

  rep(i, min(a, 9999LL) + 1) { dp[0][i] = 0; }
  VP.push(make_pair(0LL, make_pair(min(a, 9999LL), 0)));
  // cout << dp[0][2] << endl;

  e = 200000;
  while (e--) {
    auto C = VP.top();
    x = C.first;         // 今の分
    y = C.second.first;  // 今の枚数
    z = C.second.second; // 今の頂点
    VP.pop();
    if (100000 > y + v_maisu[z] && dp[z][y + v_maisu[z]] > x + v_hun[z]) {
      VP.push(make_pair(x + v_hun[z], make_pair(y + v_maisu[z], z)));
      k = y + v_maisu[z];
      while (dp[z][k] > x + v_hun[z]) {
        dp[z][k] = x + v_hun[z];
        k--;
      }
    }
    for (edge i : g[z]) {
      p = i.cost;
      q = i.to;
      r = i.maisu;
      if (y >= r && dp[q][y - r] > x + p) {
        k = y - r;
        while (dp[q][k] > x + p) {
          dp[q][k] = x + p;
          if (k == 0) {
            // cout << x + p << " " << y - r << " " << q << endl;
            t--;
            break;
          }
          k--;
        }
        VP.push(make_pair(x + p, make_pair(y - r, q)));
      }
    }
  }

  rep(i, n - 1) { cout << dp[i + 1][0] << endl; }
}