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

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

template <typename T>
vector<T> dijkstra(const vector<vector<pair<int, T>>> &G, int source) {
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;

  vector<T> dist(G.size(), INF);
  dist[source] = 0;

  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, source);

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;

    for (auto edge : G[v]) {
      if (dist[edge.first] > dist[v] + edge.second) {
        dist[edge.first] = dist[v] + edge.second;
        que.emplace(dist[edge.first], edge.first);
      }
    }
  }

  return dist;
}

int node(int i, int j) { return i * 2500 + j; }

int main() {
  int N, M;
  long long S;
  cin >> N >> M >> S;
  S = min(S, 2499LL);

  vector<vector<pair<int, long long>>> G(N * 2500);
  for (int i = 0; i < M; ++i) {
    int u, v, a;
    long long b;
    cin >> u >> v >> a >> b;
    --u;
    --v;
    for (int j = a; j < 2500; ++j) {
      G[node(u, j)].emplace_back(node(v, j - a), b);
      G[node(v, j)].emplace_back(node(u, j - a), b);
    }
  }

  for (int i = 0; i < N; ++i) {
    long long c, d;
    cin >> c >> d;
    for (int j = 0; j + c < 2500; ++j) {
      G[node(i, j)].emplace_back(node(i, j + c), d);
    }
  }

  auto dist = dijkstra(G, S);
  for (int i = 1; i < N; ++i) {
    cout << *min_element(begin(dist) + node(i, 0), begin(dist) + node(i + 1, 0))
         << '\\n';
  }
}

Error: -11

Fixed submission:

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

using p = tuple<int, long long, long long>;
int N, M;
long long S;
vector<vector<p>> G;
long long C[51] = {}, D[51] = {};
long long res[51] = {};

long long dist[51][5100] = {};
long long const INF = 1001001001001001001;

void solve(int k, long long l) {
  for (int i = 0; i < G[k].size(); ++i) {
    get<1>(G[k][i]) -= l;
    get<2>(G[k][i]) += ((l + C[k] - 1) / C[k]) * D[k];
  }

  using P = tuple<long long, long long, int>;
  priority_queue<P, vector<P>, greater<P>> Q;
  for (int j = 0; j <= 5000; ++j) {
    dist[0][j] = ((max(j - S, 0LL) + C[0] - 1) / C[0]) * D[0];
    Q.emplace(dist[0][j], j, 0);
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j <= 5000; ++j)
      dist[i][j] = INF;
  }

  while (!Q.empty()) {
    auto [d, s, v] = Q.top();
    Q.pop();
    if (dist[v][s] < d)
      continue;

    for (auto [to, a, b] : G[v]) {
      if (s < a || s - a > 5000)
        continue;
      if (dist[to][s - a] > d + b) {
        dist[to][s - a] = d + b;
        Q.emplace(d + b, s - a, to);
      }
    }
  }

  for (int i = 1; i < N; ++i) {
    for (int j = 0; j <= 5000; ++j) {
      res[i] = min(res[i], dist[i][j]);
    }
  }

  for (int i = 0; i < G[k].size(); ++i) {
    get<1>(G[k][i]) += l;
    get<2>(G[k][i]) -= ((l + C[k] - 1) / C[k]) * D[k];
  }
}

int main() {
  cin >> N >> M >> S;
  G.resize(N);
  for (int i = 0; i < N; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    G[u - 1].emplace_back(v - 1, a, b);
    G[v - 1].emplace_back(u - 1, a, b);
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }

  for (int i = 1; i < N; ++i)
    res[i] = INF;

  for (int k = 0; k < N; k++) {
    for (long long l = 0; l <= 5000; l++) {
      solve(k, l);
    }
  }

  for (int i = 1; i < N; ++i)
    cout << res[i] << '\\n';
}