Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) {
    is >> t;
  }
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (T t : v) {
    os << t << " ";
  }
  os << "\n";
  return os;
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

vi c, d;

struct edge {
  int to, a, b;
};

vector<vl> dijkstra(P start, const vector<vector<edge>> &v) {
  int n = v.size();
  vector<vl> dist(n, vl(6000, linf));
  priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> q;
  q.emplace(0LL, start);
  dist[start.first][start.second] = 0;
  while (!q.empty()) {
    auto p = q.top();
    //        cout << p.second.first << " " << p.second.second << endl;
    q.pop();
    if (dist[p.second.first][p.second.second] < p.first)
      continue;
    for (auto e : v[p.second.first]) {
      if (p.second.second - e.a < 0)
        continue;
      if (chmin(dist[e.to][p.second.second - e.a], p.first + e.b)) {
        q.push({p.first + e.b, {e.to, p.second.second - e.a}});
      }
    }
    int nc = c[p.second.first];
    int nd = d[p.second.first];
    if (p.second.second + nc < 6000) {
      if (chmin(dist[p.second.first][p.second.second + nc], p.first + nd)) {
        q.push({p.first + nd, {p.second.first, p.second.second + nc}});
      }
    }
  }
  return dist;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m, s;
  cin >> n >> m >> s;
  vector<vector<edge>> G(n);
  rep(_, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].pb(edge{v, a, b});
    G[v].pb(edge{u, a, b});
  }
  c.resize(n);
  d.resize(n);
  rep(i, n) cin >> c[i] >> d[i];
  auto v = dijkstra({0, s}, G);
  rep2(i, 1, n) {
    ll ans = linf;
    rep(j, 6000) chmin(ans, v[i][j]);
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) {
    is >> t;
  }
  return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (T t : v) {
    os << t << " ";
  }
  os << "\n";
  return os;
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

vi c, d;

struct edge {
  int to, a, b;
};

vector<vl> dijkstra(P start, const vector<vector<edge>> &v) {
  int n = v.size();
  vector<vl> dist(n, vl(6000, linf));
  priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> q;
  q.emplace(0LL, start);
  dist[start.first][start.second] = 0;
  while (!q.empty()) {
    auto p = q.top();
    //        cout << p.second.first << " " << p.second.second << endl;
    q.pop();
    if (dist[p.second.first][p.second.second] < p.first)
      continue;
    for (auto e : v[p.second.first]) {
      if (p.second.second - e.a < 0)
        continue;
      if (chmin(dist[e.to][p.second.second - e.a], p.first + e.b)) {
        q.push({p.first + e.b, {e.to, p.second.second - e.a}});
      }
    }
    int nc = c[p.second.first];
    int nd = d[p.second.first];
    if (p.second.second + nc < 6000) {
      if (chmin(dist[p.second.first][p.second.second + nc], p.first + nd)) {
        q.push({p.first + nd, {p.second.first, p.second.second + nc}});
      }
    }
  }
  return dist;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m, s;
  cin >> n >> m >> s;
  vector<vector<edge>> G(n);
  rep(_, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].pb(edge{v, a, b});
    G[v].pb(edge{u, a, b});
  }
  c.resize(n);
  d.resize(n);
  rep(i, n) cin >> c[i] >> d[i];
  auto v = dijkstra({0, min(s, 5999)}, G);
  rep2(i, 1, n) {
    ll ans = linf;
    rep(j, 6000) chmin(ans, v[i][j]);
    cout << ans << endl;
  }
}