Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
template <class W> struct edge {
  int from, to;
  W a, b;
  edge(int from, int to, W a, W b) : from(from), to(to), a(a), b(b) {}
};
template <class W> using node = vector<edge<W>>;
template <class W> using graph = vector<node<W>>;
template <class W>
void addedge(graph<W> &g, int from, int to, W a, W b,
             bool bidirectional = false) {
  g[from].emplace_back(edge<W>(from, to, a, b));
  if (bidirectional)
    g[to].emplace_back(edge<W>(to, from, a, b));
}

class Solution {
public:
  void solve() {
    int n, m, s;
    cin >> n >> m >> s;
    graph<int> g(n);
    for (int i = 0; i < m; i++) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      addedge(g, u - 1, v - 1, a, b, true);
    }
    vector<int> c(n), d(n);
    for (int i = 0; i < n; i++)
      cin >> c[i] >> d[i];
    vector<vector<long long>> dp(n,
                                 vector<long long>(2501, 0x3f3f3f3f3f3f3f3f));
    using state = tuple<long long, int, int>;
    priority_queue<state, vector<state>, greater<state>> q;
    q.push(make_tuple(0, 0, s));
    while (!q.empty()) {
      long long c_cost;
      int c_u, c_s;
      tie(c_cost, c_u, c_s) = q.top();
      q.pop();
      if (dp[c_u][c_s] <= c_cost)
        continue;
      dp[c_u][c_s] = c_cost;
      if (c_s < 2500) {
        q.push(make_tuple(c_cost + d[c_u], c_u, min(c_s + c[c_u], 2500)));
      }
      for (auto e : g[c_u]) {
        if (c_s - e.a >= 0)
          q.push(make_tuple(c_cost + e.b, e.to, c_s - e.a));
      }
    }
    for (int i = 1; i < n; i++) {
      long long ans = 0x3f3f3f3f3f3f3f3f;
      for (int j = 0; j <= 2500; j++) {
        ans = min(ans, dp[i][j]);
      }
      cout << ans << "\n";
    }
    return;
  };
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Solution solution;
  solution.solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
template <class W> struct edge {
  int from, to;
  W a, b;
  edge(int from, int to, W a, W b) : from(from), to(to), a(a), b(b) {}
};
template <class W> using node = vector<edge<W>>;
template <class W> using graph = vector<node<W>>;
template <class W>
void addedge(graph<W> &g, int from, int to, W a, W b,
             bool bidirectional = false) {
  g[from].emplace_back(edge<W>(from, to, a, b));
  if (bidirectional)
    g[to].emplace_back(edge<W>(to, from, a, b));
}

class Solution {
public:
  void solve() {
    int n, m, s;
    cin >> n >> m >> s;
    graph<int> g(n);
    for (int i = 0; i < m; i++) {
      int u, v, a, b;
      cin >> u >> v >> a >> b;
      addedge(g, u - 1, v - 1, a, b, true);
    }
    vector<int> c(n), d(n);
    for (int i = 0; i < n; i++)
      cin >> c[i] >> d[i];
    vector<vector<long long>> dp(n,
                                 vector<long long>(2501, 0x3f3f3f3f3f3f3f3f));
    using state = tuple<long long, int, int>;
    priority_queue<state, vector<state>, greater<state>> q;
    q.push(make_tuple(0, 0, min(s, 2500)));
    while (!q.empty()) {
      long long c_cost;
      int c_u, c_s;
      tie(c_cost, c_u, c_s) = q.top();
      q.pop();
      if (dp[c_u][c_s] <= c_cost)
        continue;
      dp[c_u][c_s] = c_cost;
      if (c_s < 2500) {
        q.push(make_tuple(c_cost + d[c_u], c_u, min(c_s + c[c_u], 2500)));
      }
      for (auto e : g[c_u]) {
        if (c_s - e.a >= 0)
          q.push(make_tuple(c_cost + e.b, e.to, c_s - e.a));
      }
    }
    for (int i = 1; i < n; i++) {
      long long ans = 0x3f3f3f3f3f3f3f3f;
      for (int j = 0; j <= 2500; j++) {
        ans = min(ans, dp[i][j]);
      }
      cout << ans << "\n";
    }
    return;
  };
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Solution solution;
  solution.solve();
  return 0;
}