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

#include <bits/stdc++.h>

#define debug(x)                                                               \\
  cout << "DEBUG"                                                              \\
       << " " << #x << ":" << x << '\\n'
#define rep(i, n)                                                              \\
  for (int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++) // 0-indexed昇順
#define rep1(i, n)                                                             \\
  for (int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i, n)                                                             \\
  for (int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n)                                                            \\
  for (int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()

using namespace std;

template <typename T> using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>; // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U> inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL << 62) - 1;
constexpr int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;

/*FUNCs=================================================*/
struct edge {
  i64 to, money, Tim;
  edge(i64 to, i64 money, i64 Tim) : to(to), money(money), Tim(Tim){};
};

/*MAIN==================================================*/
signed main() {
  int START_TIME = clock();
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin cout 高速化
  //    cout << fixed << setprecision(15);

  i64 n, m, s;
  cin >> n >> m >> s;
  chmin(s, 2500);

  vec<edge> graph[55][2505];
  //    memset(graph, 0, sizeof(graph));
  i64 u, v, a, b;
  rep(i, m) {
    cin >> u >> v >> a >> b;
    --u, --v;
    for (i32 sil = 0; sil <= 2500; ++sil)
      if (sil - a >= 0) {
        graph[u][sil].emplace_back(v, sil - a, b);
        graph[v][sil].emplace_back(u, sil - a, b);
      }
  }

  i64 c, d;
  rep(i, n) {
    cin >> c >> d;
    for (i32 sil = 0; sil < 2500; ++sil) {
      graph[i][sil].emplace_back(i, min<i64>(sil + c, 2500), d);
    }
  }

  using tup = tuple<i64, i32, i32>;
  minheap<tup> heap; // time, to, silver
  vec<vl> TimeToReach(n, vl(2501, infll));
  TimeToReach[0][s] = 0;
  heap.emplace(0, 0, s);
  while (heap.size()) {
    i64 t, u_to, u_sil;
    tie(t, u_to, u_sil) = heap.top();
    heap.pop();
    for (auto e : graph[u_to][u_sil]) {
      if (!chmin(TimeToReach[e.to][e.money], TimeToReach[u_to][u_sil] + e.Tim))
        continue;
      heap.emplace(TimeToReach[e.to][e.money], e.to, e.money);
    }
  }

  i64 output;
  for (int i = 1; i < n; ++i) {
    output = infll;
    rep(sil, 2501) { chmin(output, TimeToReach[i][sil]); }
    cout << output << '\\n';
  }

  // printf("ExecutionTime: %d
  // /ms\\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define debug(x)                                                               \\
  cout << "DEBUG"                                                              \\
       << " " << #x << ":" << x << '\\n'
#define rep(i, n)                                                              \\
  for (int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++) // 0-indexed昇順
#define rep1(i, n)                                                             \\
  for (int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i, n)                                                             \\
  for (int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n)                                                            \\
  for (int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()

using namespace std;

template <typename T> using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>; // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U> inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL << 62) - 1;
constexpr int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;

struct edge {
  i32 to, silver, cost;
  edge(i32 to, i32 silver, i32 cost) : to(to), silver(silver), cost(cost){};
};

/*FUNCs=================================================*/

/*MAIN==================================================*/
signed main() {
  int START_TIME = clock();
  cin.tie(nullptr);
  ios::sync_with_stdio(false); // cin cout 高速化
  //    cout << fixed << setprecision(15);

  int n, m, s;
  cin >> n >> m >> s;
  vec<edge> g[n][2550];

  i32 u, v, a, b;
  rep(i, m) {
    cin >> u >> v >> a >> b;
    --u, --v;
    for (i32 silver = 0; silver <= 2500; ++silver)
      if (silver - a >= 0) {
        g[u][silver].emplace_back(v, silver - a, b);
        g[v][silver].emplace_back(u, silver - a, b);
      }
  }

  i32 c, d;
  rep(i, n) {
    cin >> c >> d;
    for (i32 silver = 0; silver <= 2500; ++silver) {
      g[i][silver].emplace_back(i, min<int>(silver + c, 2500), d);
    }
  }

  using tup = tuple<i32, i32, i32>; // cost, to, silver
  minheap<tup> heap;
  vii Time(n, vi(2550, inf));
  Time[0][min<int>(s, 2500)] = 0;
  heap.emplace(0, 0, s);

  while (heap.size()) {
    i32 t, node, silver;
    tie(t, node, silver) = heap.top();
    heap.pop();
    for (auto e : g[node][silver]) {
      //            if(Time[e.to][e.silver] != inf) continue;
      //            debug(Time[e.to][e.silver]);
      if (!chmin(Time[e.to][e.silver], Time[node][silver] + e.cost))
        continue;
      heap.emplace(Time[e.to][e.silver], e.to, e.silver);
    }
  }

  i32 output;
  rep1(i, n - 1) {
    output = inf;
    for (i32 silver = 0; silver <= 2500; ++silver) {
      chmin(output, Time[i][silver]);
    }
    cout << output << '\\n';
  }

  // printf("ExecutionTime: %d
  // /ms\\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}