Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m, s;

struct S {
  int from, coin, cost;
  bool operator>(const S &s) const { return cost > s.cost; }
};

struct edge {
  int to, fee, cost;
};

vector<edge> G[51];
int sil[51], tim[51];
int d[51][2501];

struct Dijkstra {
  Dijkstra() {}
  void calc() {
    REP(i, n) REP(j, 2501) d[i][j] = INF;
    if (s >= 2500)
      s = 2500;
    d[0][s] = 0;
    priority_queue<S, vector<S>, greater<S>> q;
    q.push({0, s, 0});
    while (!q.empty()) {
      S p = q.top();
      q.pop();
      int from = p.from;
      int coin = p.coin;
      int cost = p.cost;
      if (d[from][coin] < cost)
        continue;
      {
        int nextCoin = coin + sil[from];
        int nextCost = cost + tim[from];
        if (d[from][nextCoin] > nextCost) {
          d[from][nextCoin] = nextCost;
          q.push({from, nextCoin, nextCost});
        }
      }
      rep(i, 0, G[from].size()) {
        int next = G[from][i].to;
        int nextCoin = coin - G[from][i].fee;
        int nextCost = cost + G[from][i].cost;
        if (nextCoin >= 0 && d[next][nextCoin] > nextCost) {
          d[next][nextCoin] = nextCost;
          q.push({next, nextCoin, nextCost});
        }
      }
    }
  }
};

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back({v, a, b});
    G[v].push_back({u, a, b});
  }
  REP(i, n) { cin >> sil[i] >> tim[i]; }
  Dijkstra dk;
  dk.calc();
  rep(i, 1, n) {
    int ans = INF;
    REP(j, 2501) ans = min(ans, d[i][j]);
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m, s;

struct S {
  int from, coin, cost;
  bool operator>(const S &s) const { return cost > s.cost; }
};

struct edge {
  int to, fee, cost;
};

vector<edge> G[51];
int sil[51], tim[51];
int d[51][2501];

struct Dijkstra {
  Dijkstra() {}
  void calc() {
    REP(i, n) REP(j, 2501) d[i][j] = INF;
    if (s >= 2500)
      s = 2500;
    d[0][s] = 0;
    priority_queue<S, vector<S>, greater<S>> q;
    q.push({0, s, 0});
    while (!q.empty()) {
      S p = q.top();
      q.pop();
      int from = p.from;
      int coin = p.coin;
      int cost = p.cost;
      if (d[from][coin] < cost)
        continue;
      {
        int nextCoin = coin + sil[from];
        int nextCost = cost + tim[from];
        if (nextCoin > 2500)
          nextCoin = 2500;
        if (d[from][nextCoin] > nextCost) {
          d[from][nextCoin] = nextCost;
          q.push({from, nextCoin, nextCost});
        }
      }
      rep(i, 0, G[from].size()) {
        int next = G[from][i].to;
        int nextCoin = coin - G[from][i].fee;
        int nextCost = cost + G[from][i].cost;
        if (nextCoin >= 0 && d[next][nextCoin] > nextCost) {
          d[next][nextCoin] = nextCost;
          q.push({next, nextCoin, nextCost});
        }
      }
    }
  }
};

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back({v, a, b});
    G[v].push_back({u, a, b});
  }
  REP(i, n) { cin >> sil[i] >> tim[i]; }
  Dijkstra dk;
  dk.calc();
  rep(i, 1, n) {
    int ans = INF;
    REP(j, 2501) ans = min(ans, d[i][j]);
    cout << ans << endl;
  }
}