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

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

template <typename T> vector<T> make_vector(int sz) { return vector<T>(sz); }

template <typename T, typename... U> auto make_vector(int sz, U... tails) {
  return vector<decltype(make_vector<T>(tails...))>(sz,
                                                    make_vector<T>(tails...));
}

template <typename T> void fill_vector(vector<T> &v, T init) {
  fill(v.begin(), v.end(), init);
}

template <typename T, typename U> void fill_vector(vector<U> &vec, T init) {
  for (auto &&v : vec) {
    fill_vector(v, init);
  }
}

template <typename T> struct Undirected_Graph {
  struct edge {
    int64_t from, to;
    T cost_money, cost_time;
  };

  int64_t n;
  vector<edge> edges;
  vector<vector<int64_t>> g;

  Undirected_Graph(int64_t n) : n(n), g(n) {}

  void add(int64_t from, int64_t to, T cost_money, T cost_time) {
    assert(0 <= from && from < n && 0 <= to && to < n);

    g[from].emplace_back(edges.size());
    g[to].emplace_back(edges.size());
    edges.push_back({from, to, cost_money, cost_time});
  }
};

int main() {
  int64_t n, m, s;
  cin >> n >> m >> s;
  vector<int64_t> us(m), vs(m), as(m), bs(m);
  for (int64_t i = 0; i < m; i++) {
    cin >> us[i] >> vs[i] >> as[i] >> bs[i];
    us[i]--;
    vs[i]--;
  }
  vector<int64_t> cs(n), ds(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> cs[i] >> ds[i];
  }

  Undirected_Graph<int64_t> g(n);
  for (int64_t i = 0; i < m; i++) {
    g.add(us[i], vs[i], as[i], bs[i]);
  }

  int64_t inf = (1LL << 60);

  auto dist = make_vector<int64_t>(n, 2501);
  fill_vector(dist, inf);

  dist[0][min<int64_t>(2500, s)] = 0;

  using U = pair<int64_t, pair<int64_t, int64_t>>;
  priority_queue<U, vector<U>, greater<>> pq;

  pq.push({dist[0][min<int64_t>(2500, s)], {0, min<int64_t>(2500, s)}});

  while (!pq.empty()) {
    int64_t t = pq.top().first;
    int64_t i = pq.top().second.first;
    int64_t j = pq.top().second.second;
    pq.pop();

    if (dist[i][j] != t) {
      continue;
    }

    if (dist[i][j] + ds[i] < dist[i][min<int64_t>(2500, j + cs[i])]) {
      dist[i][min<int64_t>(2500, j + cs[i])] = dist[i][j] + ds[i];
      pq.push({dist[i][min<int64_t>(2500, j + cs[i])],
               {i, min<int64_t>(2500, j + cs[i])}});
    }

    for (int id : g.g[i]) {
      auto &e = g.edges[id];

      int to = e.from ^ e.to ^ i;

      if (j - e.cost_money < 0) {
        continue;
      }

      if (dist[i][j] + e.cost_time < dist[to][j - e.cost_money]) {
        dist[to][j - e.cost_money] = dist[i][j] + e.cost_time;
        pq.push({dist[to][j - e.cost_money], {to, j - e.cost_money}});
      }
    }
  }

  for (int64_t t = 1; t < n; t++) {
    cout << *min_element(dist[t].begin(), dist[t].end()) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

template <typename T> vector<T> make_vector(int sz) { return vector<T>(sz); }

template <typename T, typename... U> auto make_vector(int sz, U... tails) {
  return vector<decltype(make_vector<T>(tails...))>(sz,
                                                    make_vector<T>(tails...));
}

template <typename T> void fill_vector(vector<T> &v, T init) {
  fill(v.begin(), v.end(), init);
}

template <typename T, typename U> void fill_vector(vector<U> &vec, T init) {
  for (auto &&v : vec) {
    fill_vector(v, init);
  }
}

template <typename T> struct Undirected_Graph {
  struct edge {
    int64_t from, to;
    T cost_money, cost_time;
  };

  int64_t n;
  vector<edge> edges;
  vector<vector<int64_t>> g;

  Undirected_Graph(int64_t n) : n(n), g(n) {}

  void add(int64_t from, int64_t to, T cost_money, T cost_time) {
    assert(0 <= from && from < n && 0 <= to && to < n);

    g[from].emplace_back(edges.size());
    g[to].emplace_back(edges.size());
    edges.push_back({from, to, cost_money, cost_time});
  }
};

int main() {
  int64_t n, m, s;
  cin >> n >> m >> s;
  vector<int64_t> us(m), vs(m), as(m), bs(m);
  for (int64_t i = 0; i < m; i++) {
    cin >> us[i] >> vs[i] >> as[i] >> bs[i];
    us[i]--;
    vs[i]--;
  }
  vector<int64_t> cs(n), ds(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> cs[i] >> ds[i];
  }

  Undirected_Graph<int64_t> g(n);
  for (int64_t i = 0; i < m; i++) {
    g.add(us[i], vs[i], as[i], bs[i]);
  }

  int64_t inf = (1LL << 60);

  auto dist = make_vector<int64_t>(n, 2501);
  fill_vector(dist, inf);

  dist[0][s] = 0;

  using U = pair<int64_t, pair<int64_t, int64_t>>;
  priority_queue<U, vector<U>, greater<>> pq;

  pq.push({dist[0][s], {0, s}});

  while (!pq.empty()) {
    int64_t t = pq.top().first;
    int64_t i = pq.top().second.first;
    int64_t j = pq.top().second.second;
    pq.pop();

    if (dist[i][j] != t) {
      continue;
    }

    if (dist[i][j] + ds[i] < dist[i][min<int64_t>(2500, j + cs[i])]) {
      dist[i][min<int64_t>(2500, j + cs[i])] = dist[i][j] + ds[i];
      pq.push({dist[i][min<int64_t>(2500, j + cs[i])],
               {i, min<int64_t>(2500, j + cs[i])}});
    }

    for (int id : g.g[i]) {
      auto &e = g.edges[id];

      int to = e.from ^ e.to ^ i;

      if (j - e.cost_money < 0) {
        continue;
      }

      if (dist[i][j] + e.cost_time < dist[to][j - e.cost_money]) {
        dist[to][j - e.cost_money] = dist[i][j] + e.cost_time;
        pq.push({dist[to][j - e.cost_money], {to, j - e.cost_money}});
      }
    }
  }

  for (int64_t t = 1; t < n; t++) {
    cout << *min_element(dist[t].begin(), dist[t].end()) << endl;
  }

  return 0;
}