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

#include <bits/stdc++.h>
using namespace std;

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
#include <queue>
#define INF 1ll << 60
typedef long long ll;
ll N, M, S, amax;
VLL A(100), B(100), C(100), D(100);

struct edge {
  ll to, time_cost, coin_cost;
};
typedef pair<ll, PLL> P;

struct graph {
  ll V;
  vector<vector<edge>> G;
  VVLL d;
  VLL ans;
  graph(ll n) { init(n); }

  void init(ll _n) {
    V = _n;
    G.resize(V);
    d.resize(V);
    ans.resize(V, 1ll << 60);
    for (int i = 0; i < V; i++) {
      d[i].resize(10000, INF);
    }
  }

  void add_edge(ll s, ll t, ll time_cost, ll coin_cost) {
    edge e;
    e.to = t;
    e.time_cost = time_cost;
    e.coin_cost = coin_cost;
    G[s].push_back(e);
  }

  void dijkstra() {
    d[0][S] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, PLL(0, S)));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      ll current_v = p.second.first;
      ll current_coin = p.second.second;
      if (d[current_v][current_coin] < p.first)
        continue;
      for (auto e : G[current_v]) {
        ll coin_cost = e.coin_cost;
        ll next_coin = current_coin - coin_cost;
        if (next_coin >= 0 &&
            d[e.to][next_coin] > (d[current_v][current_coin] + e.time_cost)) {
          d[e.to][next_coin] = d[current_v][current_coin] + e.time_cost;
          que.push(P(d[e.to][next_coin], PLL(e.to, next_coin)));
        }
      };
      ll nextC = min(amax * V, current_coin + C[current_v]);
      if (current_coin < amax * V &&
          d[current_v][nextC] > (d[current_v][current_coin] + D[current_v])) {
        d[current_v][nextC] = d[current_v][current_coin] + D[current_v];
        que.push(P(d[current_v][nextC], PLL(current_v, nextC)));
      }
    }
    rep(i, N) rep(j, amax * V) { chmin(ans[i], d[i][j]); }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> S;
  VLL u(M), v(M);

  graph g(N);
  rep(i, M) {
    cin >> u[i] >> v[i] >> A[i] >> B[i];
    u[i]--, v[i]--;
    g.add_edge(u[i], v[i], B[i], A[i]);
    g.add_edge(v[i], u[i], B[i], A[i]);
    chmax(amax, A[i]);
  }
  chmin(S, amax * N);

  rep(i, N) { cin >> C[i] >> D[i]; }
  g.dijkstra();
  FOR(i, 1, N) { cout << g.ans[i] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
#include <queue>
#define INF LONG_MAX
typedef long long ll;
int N, M, S;
VLL a(100), b(100), c(100), D(100);
struct edge {
  ll to, cost, ti;
};
typedef pair<ll, PLL> P;

struct graph {
  ll V;
  vector<vector<edge>> G;
  VVLL d;
  VLL dd;
  graph(ll n) { init(n); }

  void init(ll n) {
    V = n;
    G.resize(V);
    d.resize(V);
    dd.resize(V, INF);
    for (int i = 0; i < V; i++) {
      d[i].resize(300);
      rep(j, 300) d[i][j] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost, ll ti) {
    edge e;
    e.to = t, e.cost = cost;
    e.ti = ti;
    G[s].push_back(e);
  }

  void dijkstra() {
    d[0][S] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, PLL(0, S)));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      ll v = p.second.first;
      ll cc = p.second.second;
      if (d[v][cc] < p.first)
        continue;
      for (auto e : G[v]) {
        ll ti = e.ti;
        if (cc - ti >= 0 && d[e.to][cc - ti] > d[v][cc] + e.cost) {
          d[e.to][cc - ti] = d[v][cc] + e.cost;
          que.push(P(d[e.to][cc - ti], PLL(e.to, cc - ti)));
        }
      }

      if (cc < 250 && d[v][cc + c[v]] > (d[v][cc] + D[v])) {
        d[v][cc + c[v]] = d[v][cc] + D[v];
        que.push(P(d[v][cc + c[v]], PLL(v, cc + c[v])));
      }
    }
    rep(i, N) rep(j, 300) { chmin(dd[i], d[i][j]); }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> S;
  VLL u(M), v(M);
  chmin(S, 250);

  graph g(N);
  rep(i, M) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--, v[i]--;
    g.add_edge(u[i], v[i], b[i], a[i]);
    g.add_edge(v[i], u[i], b[i], a[i]);
  }
  rep(i, N) { cin >> c[i] >> D[i]; }
  g.dijkstra();
  FOR(i, 1, N) { cout << g.dd[i] << endl; }
  return 0;
}