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

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

#define putchar(x) cout << (x)
#define repeat(x)                                                              \\
  int _ = 0;                                                                   \\
  _ < (x);                                                                     \\
  ++_

template <typename T> constexpr auto range(T start, T stop, T step) {
  struct iterator {
    T i, step;
    bool operator!=(const iterator &other) const { return i != other.i; }
    auto &operator++() {
      i += step;
      return *this;
    }
    auto &operator*() { return i; }
  };
  struct iterable_wrapper {
    T start, stop, step;
    auto begin() const { return iterator{start, step}; }
    auto end() const { return iterator{stop, step}; }
    size_t size() const { return (stop - start) / step; }

    iterable_wrapper(T start_, T stop_, T step_)
        : start(start_), stop(stop_), step(step_) {
      stop = step > 0 ? max(start, stop) : min(start, stop);
      stop += (step - (stop - start) % step) % step;
    }
  };
  return iterable_wrapper(start, stop, step);
};
template <typename T> constexpr auto range(T start, T stop) {
  return range(start, stop, T(1));
}
template <typename T> constexpr auto range(T stop) {
  return range(T(0), stop, T(1));
}

template <typename T, typename Iter = decltype(begin(declval<T>()))>
constexpr auto printer(T &&iterable) {
  struct iterator {
    Iter iter, ed;
    auto operator!=(const iterator &other) const {
      auto ret = (iter != other.iter);
      if (not ret)
        cout << '\\n';
      return ret;
    }
    auto &operator++() {
      ++iter;
      if (iter != ed)
        cout << ' ';
      return *this;
    }
    auto &operator*() { return *iter; }
  };
  struct iterable_wrapper {
    T iterable;
    auto begin() const {
      return iterator{std::begin(iterable), std::end(iterable)};
    }
    auto end() const {
      return iterator{std::end(iterable), std::end(iterable)};
    }
  };
  return iterable_wrapper{forward<T>(iterable)};
};

template <size_t... Is, typename T> auto getis(const T &t) {
  return tie(get<Is>(t)...);
}
template <class T> void setmax(T &a, const T &b) { a = max(a, b); }
template <class T> void setmin(T &a, const T &b) { a = min(a, b); }

template <typename T> struct is_const_char_arr_ref : false_type {};
template <size_t N>
struct is_const_char_arr_ref<char const (&)[N]> : true_type {};
template <typename T, typename = void> struct is_container : false_type {};
template <typename T>
struct is_container<T,
                    conditional_t<false, decltype(begin(declval<T>())), void>>
    : true_type {};
template <class T>
using IsC = typename enable_if<is_container<T>::value and
                               not is_same<T, string>::value>::type;
template <class T>
using NotC = typename enable_if<not is_container<T>::value or
                                is_same<T, string>::value>::type;
template <class T> inline IsC<T> print_1(const T &v);
template <class T> inline NotC<T> print_1(const T &x) { cout << x; }
template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; };
inline void print_1(const tuple<> &) { cout << "()"; };
template <size_t L, size_t I, class T> void print_tuple(const T &t) {
  if (I != 0)
    cout << ", ";
  print_1(get<I>(t));
  if (I + 1 < L)
    print_tuple<L, (I + 1) % L>(t);
}
template <class... T> inline void print_1(const tuple<T...> &x) {
  cout << "(";
  print_tuple<sizeof...(T), 0, tuple<T...>>(x);
  cout << ")";
}
inline void print_n() {}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail);
template <class T, class U> inline void print_1(const pair<T, U> &p) {
  cout << "(";
  print_1(p.first);
  cout << ", ";
  print_1(p.second);
  cout << ")";
}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail) {
  print_1(head);
  if (sizeof...(tail))
    cout << " ";
  print_n(tail...);
}
template <class T> inline IsC<T> print_1(const T &v) {
  cout << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      cout << ", ";
    print_1(*it);
  }
  cout << "]";
}
template <class... T> inline void print(const T &...args) {
  print_n(args...);
  putchar('\\n');
}
inline void read() {}
template <class T, class... U> inline void read(T &head, U &...tail) {
  cin >> head;
  read(tail...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static int fastio = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(17);
  return 0;
}();

template <class T> void print_dbg(const string &s, T &&x) {
  if (is_const_char_arr_ref<T>::value) {
    print_n(x);
  } else {
    print_n(s, "=", x);
  }
}
#define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define dbg1(a)                                                                \\
  print_dbg(#a, a);                                                            \\
  cout << endl;
#define dbg2(a, b)                                                             \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg1(b);
#define dbg3(a, b, c)                                                          \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg2(b, c);
#define dbg4(a, b, c, d)                                                       \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg3(b, c, d);
#define dbg5(a, b, c, d, e)                                                    \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg4(b, c, d, e);
#define dbg6(a, b, c, d, e, f)                                                 \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg5(b, c, d, e, f);
#define dbg7(a, b, c, d, e, f, g)                                              \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg6(b, c, d, e, f, g);
#define dbg8(a, b, c, d, e, f, g, h)                                           \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg7(b, c, d, e, f, g, h);
#define debug(...)                                                             \\
  SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1)          \\
  (__VA_ARGS__)
//}}}
using PII = pair<int, int>;
using LL = long long;
using TLII = tuple<LL, int, int>;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 55;
const int MAX_S = 2505;

struct edge {
  int to, silver, time;
};

vector<edge> G[MAX_N];
LL d[MAX_N][MAX_S];

struct Solution {
  Solution(int) {
    int N, M, S;
    read(N, M, S);
    setmin(S, MAX_S - 1);

    for (repeat(M)) {
      int u, v, a, b;
      read(u, v, a, b);
      G[u].push_back({v, a, b});
      G[v].push_back({u, a, b});
    }
    vector<LL> C(N + 1), D(N + 1);
    for (int i : range(1, N + 1)) {
      read(C[i], D[i]);
    }

    int ok = 0;
    vector<bool> done(N + 1, false);

    priority_queue<TLII, vector<TLII>, greater<TLII>> pq;
    memset(d, INF, sizeof(d));
    d[1][S] = 0;
    pq.push({0, 1, S});

    while (pq.size()) {
      auto [dist, v, s] = pq.top();
      pq.pop();

      if (not done[v]) {
        done[v] = true;
        ok += 1;
        if (ok == N) {
          break;
        }
      }

      if (dist > d[v][s]) {
        continue;
      }

      for (int i = 1; s + C[v] * i < MAX_S; ++i) {
        auto s1 = s + C[v] * i;
        if (d[v][s1] > d[v][s] + D[v] * i) {
          d[v][s1] = d[v][s] + D[v] * i;
          pq.push({d[v][s1], v, s1});
        }
      }

      for (auto &e : G[v]) {
        auto s1 = s - e.silver;
        if (s1 >= 0 and d[e.to][s1] > d[v][s] + e.time) {
          d[e.to][s1] = d[v][s] + e.time;
          pq.push({d[e.to][s1], e.to, s1});
        }
      }
    }

    for (int i = 2; i <= N; ++i) {
      LL ans = LLINF;
      for (int j = 0; j < MAX_S; ++j) {
        setmin(ans, d[i][j]);
      }
      print(ans);
    }
  }
};

int main() {
  int T = 1;
  // cin >> T;
  for (int i = 1; i <= T; ++i) {
    ignore = Solution(i);
  }
  return 0;
}


Error: 0

Fixed submission:

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

#define putchar(x) cout << (x)
#define repeat(x)                                                              \\
  int _ = 0;                                                                   \\
  _ < (x);                                                                     \\
  ++_

template <typename T> constexpr auto range(T start, T stop, T step) {
  struct iterator {
    T i, step;
    bool operator!=(const iterator &other) const { return i != other.i; }
    auto &operator++() {
      i += step;
      return *this;
    }
    auto &operator*() { return i; }
  };
  struct iterable_wrapper {
    T start, stop, step;
    auto begin() const { return iterator{start, step}; }
    auto end() const { return iterator{stop, step}; }
    size_t size() const { return (stop - start) / step; }

    iterable_wrapper(T start_, T stop_, T step_)
        : start(start_), stop(stop_), step(step_) {
      stop = step > 0 ? max(start, stop) : min(start, stop);
      stop += (step - (stop - start) % step) % step;
    }
  };
  return iterable_wrapper(start, stop, step);
};
template <typename T> constexpr auto range(T start, T stop) {
  return range(start, stop, T(1));
}
template <typename T> constexpr auto range(T stop) {
  return range(T(0), stop, T(1));
}

template <typename T, typename Iter = decltype(begin(declval<T>()))>
constexpr auto printer(T &&iterable) {
  struct iterator {
    Iter iter, ed;
    auto operator!=(const iterator &other) const {
      auto ret = (iter != other.iter);
      if (not ret)
        cout << '\\n';
      return ret;
    }
    auto &operator++() {
      ++iter;
      if (iter != ed)
        cout << ' ';
      return *this;
    }
    auto &operator*() { return *iter; }
  };
  struct iterable_wrapper {
    T iterable;
    auto begin() const {
      return iterator{std::begin(iterable), std::end(iterable)};
    }
    auto end() const {
      return iterator{std::end(iterable), std::end(iterable)};
    }
  };
  return iterable_wrapper{forward<T>(iterable)};
};

template <size_t... Is, typename T> auto getis(const T &t) {
  return tie(get<Is>(t)...);
}
template <class T> void setmax(T &a, const T &b) { a = max(a, b); }
template <class T> void setmin(T &a, const T &b) { a = min(a, b); }

template <typename T> struct is_const_char_arr_ref : false_type {};
template <size_t N>
struct is_const_char_arr_ref<char const (&)[N]> : true_type {};
template <typename T, typename = void> struct is_container : false_type {};
template <typename T>
struct is_container<T,
                    conditional_t<false, decltype(begin(declval<T>())), void>>
    : true_type {};
template <class T>
using IsC = typename enable_if<is_container<T>::value and
                               not is_same<T, string>::value>::type;
template <class T>
using NotC = typename enable_if<not is_container<T>::value or
                                is_same<T, string>::value>::type;
template <class T> inline IsC<T> print_1(const T &v);
template <class T> inline NotC<T> print_1(const T &x) { cout << x; }
template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; };
inline void print_1(const tuple<> &) { cout << "()"; };
template <size_t L, size_t I, class T> void print_tuple(const T &t) {
  if (I != 0)
    cout << ", ";
  print_1(get<I>(t));
  if (I + 1 < L)
    print_tuple<L, (I + 1) % L>(t);
}
template <class... T> inline void print_1(const tuple<T...> &x) {
  cout << "(";
  print_tuple<sizeof...(T), 0, tuple<T...>>(x);
  cout << ")";
}
inline void print_n() {}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail);
template <class T, class U> inline void print_1(const pair<T, U> &p) {
  cout << "(";
  print_1(p.first);
  cout << ", ";
  print_1(p.second);
  cout << ")";
}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail) {
  print_1(head);
  if (sizeof...(tail))
    cout << " ";
  print_n(tail...);
}
template <class T> inline IsC<T> print_1(const T &v) {
  cout << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      cout << ", ";
    print_1(*it);
  }
  cout << "]";
}
template <class... T> inline void print(const T &...args) {
  print_n(args...);
  putchar('\\n');
}
inline void read() {}
template <class T, class... U> inline void read(T &head, U &...tail) {
  cin >> head;
  read(tail...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static int fastio = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(17);
  return 0;
}();

template <class T> void print_dbg(const string &s, T &&x) {
  if (is_const_char_arr_ref<T>::value) {
    print_n(x);
  } else {
    print_n(s, "=", x);
  }
}
#define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define dbg1(a)                                                                \\
  print_dbg(#a, a);                                                            \\
  cout << endl;
#define dbg2(a, b)                                                             \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg1(b);
#define dbg3(a, b, c)                                                          \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg2(b, c);
#define dbg4(a, b, c, d)                                                       \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg3(b, c, d);
#define dbg5(a, b, c, d, e)                                                    \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg4(b, c, d, e);
#define dbg6(a, b, c, d, e, f)                                                 \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg5(b, c, d, e, f);
#define dbg7(a, b, c, d, e, f, g)                                              \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg6(b, c, d, e, f, g);
#define dbg8(a, b, c, d, e, f, g, h)                                           \\
  print_dbg(#a, a);                                                            \\
  cout << ", ";                                                                \\
  dbg7(b, c, d, e, f, g, h);
#define debug(...)                                                             \\
  SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1)          \\
  (__VA_ARGS__)
//}}}
using PII = pair<int, int>;
using LL = long long;
using TLII = tuple<LL, int, int>;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 55;
const int MAX_S = 2505;

struct edge {
  int to, silver, time;
};

vector<edge> G[MAX_N];
LL d[MAX_N][MAX_S];

struct Solution {
  Solution(int) {
    int N, M, S;
    read(N, M, S);
    for (repeat(M)) {
      int u, v, a, b;
      read(u, v, a, b);
      G[u].push_back({v, a, b});
      G[v].push_back({u, a, b});
    }
    vector<LL> C(N + 1), D(N + 1);
    for (int i : range(1, N + 1)) {
      read(C[i], D[i]);
    }

    int ok = 0;
    vector<bool> done(N + 1, false);

    priority_queue<TLII, vector<TLII>, greater<TLII>> pq;
    memset(d, INF, sizeof(d));
    d[1][S] = 0;
    pq.push({0, 1, S});

    while (pq.size()) {
      auto [dist, v, s] = pq.top();
      pq.pop();

      if (not done[v]) {
        done[v] = true;
        ok += 1;
        if (ok == N) {
          break;
        }
      }

      if (dist > d[v][s]) {
        continue;
      }

      for (int i = 1; s + C[v] * i < MAX_S; ++i) {
        auto s1 = s + C[v] * i;
        if (d[v][s1] > d[v][s] + D[v] * i) {
          d[v][s1] = d[v][s] + D[v] * i;
          pq.push({d[v][s1], v, s1});
        }
      }

      for (auto &e : G[v]) {
        auto s1 = s - e.silver;
        if (s1 >= 0 and d[e.to][s1] > d[v][s] + e.time) {
          d[e.to][s1] = d[v][s] + e.time;
          pq.push({d[e.to][s1], e.to, s1});
        }
      }
    }

    for (int i = 2; i <= N; ++i) {
      LL ans = LLINF;
      for (int j = 0; j < MAX_S; ++j) {
        setmin(ans, d[i][j]);
      }
      print(ans);
    }
  }
};

int main() {
  int T = 1;
  // cin >> T;
  for (int i = 1; i <= T; ++i) {
    ignore = Solution(i);
  }
  return 0;
}