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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

struct edge {
  int to;
  ll cost;
};

int n, m, s;
const int S = 3000;

vector<ll> dijkstra(vector<edge> g[], int s, int V) {

  vector<ll> dist(V, LINF);

  priority_queue<pll, vector<pll>, greater<pll>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    ll cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if (dist[idx] < cost)
      continue;
    for (auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if (dist[e.to] <= next_cost)
        continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

void solve() {
  cin >> n >> m >> s;
  chmin(s, S - 100);
  vector<edge> G[n * (S + 1)];

  auto lift = [](int v, int c) { return v * (S + 1) + c; };

  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    rep(c, S - a) {
      G[lift(u, c + a)].pb({lift(v, c), b});
      G[lift(v, c + a)].pb({lift(u, c), b});
    }
  }

  rep(v, n) {
    rep(i, S - 1) { G[lift(v, i + 1)].pb({lift(v, i), 0}); }

    int c, d;
    cin >> c >> d;
    chmin(c, S);

    rep(j, S - c) G[lift(v, j)].pb({lift(v, j + c), d});
  }

  auto dist = dijkstra(G, lift(0, s), n * S + 100);

  rep(i, n) {
    if (!i)
      continue;
    cout << dist[lift(i, 0)] << endl;
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

struct edge {
  int to;
  ll cost;
};

int n, m, s;
const int S = 3000;

vector<ll> dijkstra(vector<edge> g[], int s, int V) {

  vector<ll> dist(V, LINF);

  priority_queue<pll, vector<pll>, greater<pll>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    ll cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if (dist[idx] < cost)
      continue;
    for (auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if (dist[e.to] <= next_cost)
        continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

void solve() {
  cin >> n >> m >> s;
  vector<edge> G[n * S + 100];

  auto lift = [](int v, int c) { return v * S + c; };

  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    rep(c, S - a) {
      G[lift(u, c + a)].pb({lift(v, c), b});
      G[lift(v, c + a)].pb({lift(u, c), b});
    }
  }

  rep(v, n) {
    rep(i, S - 1) { G[lift(v, i + 1)].pb({lift(v, i), 0}); }

    int c, d;
    cin >> c >> d;
    chmin(c, S);

    rep(j, S - c + 1) G[lift(v, j)].pb({lift(v, j + c), d});
  }

  auto dist = dijkstra(G, lift(0, s), n * S + 100);

  rep(i, n) {
    if (!i)
      continue;
    cout << dist[lift(i, 0)] << endl;
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}