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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
const ll inf = 1e+18;
const int MAXI = 2500;

using pll = pair<ll, ll>; // money,time
using Edge = pair<int, pll>;
using Graph = vector<vector<Edge>>;
int n, m;
ll s;
Graph G;
vector<ll> c, d;
int main(void) {
  cin >> n >> m >> s;
  G.assign(n, vector<Edge>());
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back(Edge(v, pll(a, b)));
    G[v].push_back(Edge(u, pll(a, b)));
  }
  c.resize(n);
  d.resize(n);
  rep(i, n) cin >> c[i] >> d[i];

  if (s >= MAXI)
    s = MAXI;
  vector<vector<ll>> dp(n, vector<ll>(MAXI + 1, inf));
  priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>>
      que; // time,edge,money
  dp[0][s] = 0;
  que.push({0, pll(0, s)});
  while (que.size()) {
    auto p = que.top();
    que.pop();
    ll t = p.first;
    int v = p.second.first;
    ll ss = p.second.second;
    if (t > dp[v][ss])
      continue;
    if (ss + c[v] <= MAXI) {
      ll ns = ss + c[v];
      ll ntime = t + d[v];
      if (chmin(dp[v][ns], ntime)) {
        que.push(make_pair(ntime, pll(v, ns)));
      }
    }

    for (auto e : G[v]) {
      if (ss < e.second.first)
        continue;
      int nv = e.first;
      ll ns = ss - e.second.first;
      ll ntime = t + e.second.second;
      if (chmin(dp[nv][ns], ntime)) {
        que.push(make_pair(ntime, pll(nv, ns)));
      }
    }
  }
  rep(i, n) {
    if (i == 0)
      continue;
    ll res = inf;
    rep(j, MAXI + 1) res = min(res, dp[i][j]);
    cout << res << endl;
  }
}

Error: -6
corrupted size vs. prev_size


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
const ll inf = 1e+18;
const int MAXI = 2500;
using pll = pair<ll, ll>; // money,time
using Edge = pair<int, pll>;
using Graph = vector<vector<Edge>>;
int main(void) {
  int n, m;
  ll s;
  cin >> n >> m >> s;
  Graph G(n, vector<Edge>());
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back(Edge(v, pll(a, b)));
    G[v].push_back(Edge(u, pll(a, b)));
  }
  vector<ll> c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];

  if (s >= MAXI)
    s = MAXI;
  vector<vector<ll>> dp(n, vector<ll>(MAXI + 1, inf));
  priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>>
      que; // time,edge,money
  dp[0][s] = 0;
  que.push({0, pll(0, s)});
  while (que.size()) {
    auto p = que.top();
    que.pop();
    ll t = p.first;
    int v = p.second.first;
    ll ss = p.second.second;
    if (t > dp[v][ss])
      continue;
    if (s + c[v] <= MAXI) {
      ll ns = ss + c[v];
      ll ntime = t + d[v];
      if (chmin(dp[v][ns], ntime)) {
        que.push(make_pair(ntime, pll(v, ns)));
      }
    }

    for (auto e : G[v]) {
      if (ss < e.second.first)
        continue;
      int nv = e.first;
      ll ns = ss - e.second.first;
      ll ntime = t + e.second.second;
      if (chmin(dp[nv][ns], ntime)) {
        que.push(make_pair(ntime, pll(nv, ns)));
      }
    }
  }
  rep(i, n) {
    if (i == 0)
      continue;
    ll res = inf;
    rep(j, MAXI + 1) res = min(res, dp[i][j]);
    cout << res << endl;
  }
}