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

#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = int(m); i < int(n); ++i)
#define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto &e : v)
    os << e << " ";
  return os;
}
template <typename T> inline int count_between(vector<T> &a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l);
} // [l, r)
inline int Log2(ll x) {
  int k;
  for (k = 0; x > 0; ++k)
    x >>= 1;
  return k;
} // number of binary digits
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;

template <typename T> struct edge {
  int v;
  T w;
  edge(int v, T w) : v(v), w(w) {}
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using Graph = vector<Edges<T>>;

template <typename T> vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);

  using PTi = pair<T, int>;
  priority_queue<PTi, vector<PTi>, greater<PTi>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);

  while (!pq.empty()) {
    T cost;
    int u;
    tie(cost, u) = pq.top();
    pq.pop();
    if (dist[u] < cost)
      continue;
    for (auto &e : G[u]) {
      auto n_cost = cost + e.w;
      if (dist[e.v] <= n_cost)
        continue;
      dist[e.v] = n_cost;
      pq.emplace(dist[e.v], e.v);
    }
  }
  return dist;
}

int main() {
  ll n, m, s;
  cin >> n >> m >> s;

  ll M = n * 50;

  Graph<ll> G(n * (M + 1));
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    rep(k, M + 1) {
      int uu, vv;
      uu = u + n * k;
      vv = v + n * (k - a);
      if (vv >= 0)
        G[uu].emplace_back(vv, b);
      uu = u + n * (k - a);
      vv = v + n * k;
      if (uu >= 0)
        G[vv].emplace_back(uu, b);
    }
  }

  Vll c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];

  rep(i, n) rep(k, M + 1) {
    int u, v;
    u = i + n * k;
    v = i + n * min(k + c[i], M);
    G[u].emplace_back(v, d[i]);
    v = i + n * (k - 1);
    if (v >= 0)
      G[u].emplace_back(v, 0);
  }

  ll ss = min(s, M) * n;
  auto dist = dijkstra(G, ss);

  rep2(i, 1, n) cout << dist[i] << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = int(m); i < int(n); ++i)
#define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &e : v)
    is >> e;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto &e : v)
    os << e << " ";
  return os;
}
template <typename T> inline int count_between(vector<T> &a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l);
} // [l, r)
inline int Log2(ll x) {
  int k;
  for (k = 0; x > 0; ++k)
    x >>= 1;
  return k;
} // number of binary digits
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;

template <typename T> struct edge {
  int v;
  T w;
  edge(int v, T w) : v(v), w(w) {}
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using Graph = vector<Edges<T>>;

template <typename T> vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);

  using PTi = pair<T, int>;
  priority_queue<PTi, vector<PTi>, greater<PTi>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);

  while (!pq.empty()) {
    T cost;
    int u;
    tie(cost, u) = pq.top();
    pq.pop();
    if (dist[u] < cost)
      continue;
    for (auto &e : G[u]) {
      auto n_cost = cost + e.w;
      if (dist[e.v] <= n_cost)
        continue;
      dist[e.v] = n_cost;
      pq.emplace(dist[e.v], e.v);
    }
  }
  return dist;
}

int main() {
  ll n, m, s;
  cin >> n >> m >> s;

  ll M = n * 50;

  Graph<ll> G(n * M);
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    rep(k, M + 1) {
      int uu, vv;
      uu = u + n * k;
      vv = v + n * (k - a);
      if (vv >= 0)
        G[uu].emplace_back(vv, b);
      uu = u + n * (k - a);
      vv = v + n * k;
      if (uu >= 0)
        G[vv].emplace_back(uu, b);
    }
  }

  Vll c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];

  rep(i, n) rep(k, M + 1) {
    int u, v;
    u = i + n * k;
    v = i + n * min(k + c[i], M);
    G[u].emplace_back(v, d[i]);
    v = i + n * (k - 1);
    if (v >= 0)
      G[u].emplace_back(v, 0);
  }

  ll ss = min(s, M) * n;
  auto dist = dijkstra(G, ss);

  rep2(i, 1, n) cout << dist[i] << endl;
  return 0;
}