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

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

const int MAX_G = 2500;

struct Edge {
  int to;
  ll w;
};
using Graph = vector<vector<Edge>>;

const ll INF = 1e15;
vector<ll> dijkstra(int s, Graph &g) {
  int n = g.size();
  vector<ll> d(n, INF);
  using P = pair<ll, int>;
  priority_queue<P, vector<P>, greater<>> que;
  d[s] = 0;
  que.push({d[s], s});
  while (!que.empty()) {
    auto tmp = que.top();
    que.pop();
    int v = tmp.second;
    if (d[v] < tmp.first)
      continue;
    for (auto &e : g[v]) {
      ll c = d[v] + e.w;
      if (c < d[e.to]) {
        d[e.to] = c;
        que.push({d[e.to], e.to});
      }
    }
  }
  return d;
}
int main() {
  int n, m;
  int s;
  cin >> n >> m >> s;
  auto vertex_of = [&](int v, int s) { return (MAX_G + 1) * v + s; };
  Graph g(n * (MAX_G + 1));
  for (int lp = 0; lp < m; lp++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= MAX_G - a; i++) {
      g[vertex_of(u, i + a)].push_back(Edge{vertex_of(v, i), b});
      g[vertex_of(v, i + a)].push_back(Edge{vertex_of(u, i), b});
    }
  }

  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j <= MAX_G; j++) {
      int tmp = min(MAX_G, j + c);
      g[vertex_of(i, j)].push_back(Edge{vertex_of(i, tmp), d});
    }
  }

  auto d = dijkstra(vertex_of(0, min(s, MAX_G)), g);

  for (int i = 1; i < n; i++) {
    ll res = INF;
    for (int j = 0; j <= MAX_G; j++) {
      res = min(res, d[vertex_of(i, j)]);
    }
    cout << res << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

const int MAX_G = 2500;

struct Edge {
  int to;
  ll w;
};
using Graph = vector<vector<Edge>>;

const ll INF = 1e15;
vector<ll> dijkstra(int s, Graph &g) {
  int n = g.size();
  vector<ll> d(n, INF);
  using P = pair<ll, int>;
  priority_queue<P, vector<P>, greater<>> que;
  d[s] = 0;
  que.push({d[s], s});
  while (!que.empty()) {
    auto tmp = que.top();
    que.pop();
    int v = tmp.second;
    if (d[v] < tmp.first)
      continue;
    for (auto &e : g[v]) {
      ll c = d[v] + e.w;
      if (c < d[e.to]) {
        d[e.to] = c;
        que.push({d[e.to], e.to});
      }
    }
  }
  return d;
}
int main() {
  int n, m;
  ll s;
  cin >> n >> m >> s;
  auto vertex_of = [&](int v, int s) { return (MAX_G + 1) * v + s; };
  Graph g(n * (MAX_G + 1));
  for (int lp = 0; lp < m; lp++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= MAX_G - a; i++) {
      g[vertex_of(u, i + a)].push_back(Edge{vertex_of(v, i), b});
      g[vertex_of(v, i + a)].push_back(Edge{vertex_of(u, i), b});
    }
  }

  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j <= MAX_G; j++) {
      int tmp = min(MAX_G, j + c);
      g[vertex_of(i, j)].push_back(Edge{vertex_of(i, tmp), d});
    }
  }

  auto d = dijkstra(vertex_of(0, s), g);

  for (int i = 1; i < n; i++) {
    ll res = INF;
    for (int j = 0; j <= MAX_G; j++) {
      res = min(res, d[vertex_of(i, j)]);
    }
    cout << res << endl;
  }

  return 0;
}