Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 5;
typedef pair<int, int> P;

// 辺に重みをつける場合
struct Edge {
  int to;
  int cost;
  int time;
  Edge(int t, int c, int r) : to(t), cost(c), time(r) {}
};

using Graph = vector<vector<Edge>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, M, S;
  cin >> N >> M >> S;
  if (S >= 2500)
    S = 2499;
  Graph G1(N);
  rep(i, M) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a;
    --b;
    G1[a].push_back(Edge(b, c, d));
    G1[b].push_back(Edge(a, c, d));
  }

  P p[N];
  rep(i, N) cin >> p[i].first >> p[i].second;

  int dist1[N][2501];
  rep(i, N) {
    rep(j, 2501) { dist1[i][j] = INF; }
  }

  priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>>
      que1;
  dist1[0][S] = 0;
  que1.push({P(0, 0), S});

  while (!que1.empty()) {
    auto l = que1.top();
    que1.pop();
    int t = l.first.first;
    int u = l.first.second;
    int c = l.second;

    if (c >= 2500)
      continue;
    if (t > dist1[u][c])
      continue;

    dist1[u][c] = t;

    for (int i = 0; i < G1[u].size(); ++i) {
      int v = G1[u][i].to;
      int d1 = G1[u][i].cost;
      int d2 = G1[u][i].time;

      if (c - d1 < 0)
        continue;
      if (dist1[v][c - d1] > dist1[u][c] + d2) {
        dist1[v][c - d1] = dist1[u][c] + d2;
        que1.push({P(t + d2, v), c - d1});
      }
    }

    int t1 = t + p[u].second;
    int c1 = c + p[u].first;

    if (c >= 2500)
      continue;
    if (dist1[u][c1] > t1) {
      dist1[u][c1] = t1;
      que1.push({P(t1, u), c1});
    }
  }

  for (int i = 1; i < N; i++) {
    int ans = INF;
    for (int j = 0; j < 2500; j++) {
      ans = min(ans, dist1[i][j]);
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 5;
typedef pair<int, int> P;

// 辺に重みをつける場合
struct Edge {
  int to;
  int cost;
  int time;
  Edge(int t, int c, int r) : to(t), cost(c), time(r) {}
};

using Graph = vector<vector<Edge>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, M, S;
  cin >> N >> M >> S;
  if (S >= 2500)
    S = 2499;
  Graph G1(N);
  rep(i, M) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a;
    --b;
    G1[a].push_back(Edge(b, c, d));
    G1[b].push_back(Edge(a, c, d));
  }

  P p[N];
  rep(i, N) cin >> p[i].first >> p[i].second;

  int dist1[N][2501];
  rep(i, N) {
    rep(j, 2501) { dist1[i][j] = INF; }
  }

  priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>>
      que1;
  dist1[0][S] = 0;
  que1.push({P(0, 0), S});

  while (!que1.empty()) {
    auto l = que1.top();
    que1.pop();
    int t = l.first.first;
    int u = l.first.second;
    int c = l.second;

    if (c >= 2500)
      continue;
    if (t > dist1[u][c])
      continue;

    dist1[u][c] = t;

    for (int i = 0; i < G1[u].size(); ++i) {
      int v = G1[u][i].to;
      int d1 = G1[u][i].cost;
      int d2 = G1[u][i].time;

      if (c - d1 < 0)
        continue;
      if (dist1[v][c - d1] > dist1[u][c] + d2) {
        dist1[v][c - d1] = dist1[u][c] + d2;
        que1.push({P(t + d2, v), c - d1});
      }
    }

    int t1 = t + p[u].second;
    int c1 = c + p[u].first;

    if (c1 >= 2500)
      continue;
    if (dist1[u][c1] > t1) {
      dist1[u][c1] = t1;
      que1.push({P(t1, u), c1});
    }
  }

  for (int i = 1; i < N; i++) {
    int ans = INF;
    for (int j = 0; j < 2500; j++) {
      ans = min(ans, dist1[i][j]);
    }
    cout << ans << endl;
  }
}