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

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const long long INF = 1e18;

struct Edge {
  int to;
  long long cost;
};

struct Dijkstra {
  using P = pair<long long, int>;
  int V;
  int s;
  const vector<vector<Edge>> &g;
  vector<long long> dist;
  vector<int> previous;

  Dijkstra(const vector<vector<Edge>> &g) : V(g.size()), g(g) {}

  void calc(int start) {
    s = start;
    dist.assign(V, INF);
    previous.assign(V, -1);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> pque;
    pque.push(P(0, s));
    while (!pque.empty()) {
      P p = pque.top();
      pque.pop();
      int v = p.second;
      if (p.first > dist[v])
        continue;
      for (Edge e : g[v]) {
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          previous[e.to] = v;
          pque.push(P(dist[e.to], e.to));
        }
      }
    }
  }
};

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  const int MAX = 2505;
  vector<vector<Edge>> g(n * (MAX + 1));
  auto idx = [&](int v, int ginka) { return ginka * n + v; };
  for (int i = 0; i < m; i++) {
    long long u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = 0; j <= MAX; j++) {
      if (j - a >= 0)
        g[idx(u, j)].push_back({idx(v, j - a), b});
      if (j + a <= MAX)
        g[idx(v, j + a)].push_back({idx(u, j), b});
    }
  }
  for (int i = 0; i < n; i++) {
    long long c, d;
    cin >> c >> d;
    for (int j = 0; j < MAX; j++) {
      g[idx(i, j)].push_back({idx(i, min(MAX, int(j + c))), d});
    }
  }
  Dijkstra D(g);
  D.calc(idx(0, min(s, MAX)));
  for (int i = 1; i < n; i++) {
    long long ans = INF;
    for (int j = 0; j <= MAX; j++) {
      ans = min(ans, D.dist[idx(i, j)]);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const long long INF = 1e18;

struct Edge {
  int to;
  long long cost;
};

struct Dijkstra {
  using P = pair<long long, int>;
  int V;
  int s;
  const vector<vector<Edge>> &g;
  vector<long long> dist;
  vector<int> previous;

  Dijkstra(const vector<vector<Edge>> &g) : V(g.size()), g(g) {}

  void calc(int start) {
    s = start;
    dist.assign(V, INF);
    previous.assign(V, -1);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> pque;
    pque.push(P(0, s));
    while (!pque.empty()) {
      P p = pque.top();
      pque.pop();
      int v = p.second;
      if (p.first > dist[v])
        continue;
      for (Edge e : g[v]) {
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          previous[e.to] = v;
          pque.push(P(dist[e.to], e.to));
        }
      }
    }
  }
};

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  const int MAX = 2505;
  vector<vector<Edge>> g(n * (MAX + 1));
  auto idx = [&](int v, int ginka) { return ginka * n + v; };
  for (int i = 0; i < m; i++) {
    long long u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = 0; j <= MAX; j++) {
      if (j - a >= 0)
        g[idx(u, j)].push_back({idx(v, j - a), b});
      if (j + a <= MAX)
        g[idx(v, j + a)].push_back({idx(u, j), b});
    }
  }
  for (int i = 0; i < n; i++) {
    long long c, d;
    cin >> c >> d;
    for (int j = 0; j < MAX; j++) {
      g[idx(i, j)].push_back({idx(i, min(MAX, int(j + c))), d});
    }
  }
  Dijkstra D(g);
  D.calc(idx(0, s));
  for (int i = 1; i < n; i++) {
    long long ans = INF;
    for (int j = 0; j <= MAX; j++) {
      ans = min(ans, D.dist[idx(i, j)]);
    }
    cout << ans << endl;
  }
  return 0;
}