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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

struct edge {
  ll to, len, cost;
  edge(ll to, ll len, ll cost) : to(to), len(len), cost(cost) {}
};

#define MAX_N 50
#define MAX_M 100
#define MAX_A 2500
int A[MAX_M], B[MAX_M], C[MAX_N], D[MAX_N];
int n, m, sil;
vector<edge> G[51];
vector<ll> _time[MAX_A + 1], min_time;
vector<int> prev[MAX_A + 1];

void dijkstra(int s) {
  rep(i, MAX_A + 1) { _time[i].resize(n, linf); }
  min_time.resize(n, linf);
  _time[sil][s] = 0;
  min_time[s] = 0;
  using P = pair<ll, pair<int, int>>; // time, (pos, sil)
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(make_pair(0, make_pair(s, sil)));

  while (!Q.empty()) {
    ll cur_time = Q.top().first;
    int cur_pos = Q.top().second.first;
    int cur_sil = Q.top().second.second;
    Q.pop();
    if (_time[cur_sil][cur_pos] < cur_time)
      continue;
    if (cur_sil != MAX_A) {
      int nx_sil = min(MAX_A, cur_sil + C[cur_pos]);
      ll nx_time = cur_time + D[cur_pos];
      if (_time[nx_sil][cur_pos] > nx_time) {
        _time[nx_sil][cur_pos] = nx_time;
        Q.push(make_pair(nx_time, make_pair(cur_pos, nx_sil)));
      }
    }
    for (edge e : G[cur_pos]) {
      ll nx_time = cur_time + e.len;
      int nx_pos = e.to;
      int nx_sil = cur_sil - e.cost;
      if (nx_sil >= 0 && nx_time < _time[nx_sil][nx_pos]) {
        _time[nx_sil][nx_pos] = nx_time;
        min_time[nx_pos] = min(min_time[nx_pos], nx_time);
        Q.push(make_pair(nx_time, make_pair(nx_pos, nx_sil)));
      }
    }
  }
}
int main() {
  cin >> n >> m >> sil;
  sil = min(sil, MAX_A);
  rep(i, m) {
    int u, v;
    cin >> u >> v >> A[i] >> B[i];
    u--, v--;
    G[u].push_back(edge(v, B[i], A[i]));
    G[v].push_back(edge(u, B[i], A[i]));
  }
  rep(i, n) { cin >> C[i] >> D[i]; }
  dijkstra(0);
  reps(i, n - 1) { cout << min_time[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

struct edge {
  ll to, len, cost;
  edge(ll to, ll len, ll cost) : to(to), len(len), cost(cost) {}
};

#define MAX_N 50
#define MAX_A 2500
int A[MAX_N], B[MAX_N], C[MAX_N], D[MAX_N];
int n, m, sil;
vector<edge> G[51];
vector<ll> _time[MAX_A + 1], min_time;
vector<int> prev[MAX_A + 1];

void dijkstra(int s) {
  rep(i, MAX_A + 1) { _time[i].resize(n, linf); }
  min_time.resize(n, linf);
  _time[sil][s] = 0;
  min_time[s] = 0;
  using P = pair<ll, pair<int, int>>; // time, (pos, sil)
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(make_pair(0, make_pair(s, sil)));

  while (!Q.empty()) {
    ll cur_time = Q.top().first;
    int cur_pos = Q.top().second.first;
    int cur_sil = Q.top().second.second;
    Q.pop();
    if (_time[cur_sil][cur_pos] < cur_time)
      continue;
    if (cur_sil != MAX_A) {
      int nx_sil = min(MAX_A, cur_sil + C[cur_pos]);
      ll nx_time = cur_time + D[cur_pos];
      if (_time[nx_sil][cur_pos] > nx_time) {
        _time[nx_sil][cur_pos] = nx_time;
        Q.push(make_pair(nx_time, make_pair(cur_pos, nx_sil)));
      }
    }
    for (edge e : G[cur_pos]) {
      ll nx_time = cur_time + e.len;
      int nx_pos = e.to;
      int nx_sil = cur_sil - e.cost;
      if (nx_sil >= 0 && nx_time < _time[nx_sil][nx_pos]) {
        _time[nx_sil][nx_pos] = nx_time;
        min_time[nx_pos] = min(min_time[nx_pos], nx_time);
        Q.push(make_pair(nx_time, make_pair(nx_pos, nx_sil)));
      }
    }
  }
}
int main() {
  cin >> n >> m >> sil;
  sil = min(sil, MAX_A);
  rep(i, m) {
    int u, v;
    cin >> u >> v >> A[i] >> B[i];
    u--, v--;
    G[u].push_back(edge(v, B[i], A[i]));
    G[v].push_back(edge(u, B[i], A[i]));
  }
  rep(i, n) { cin >> C[i] >> D[i]; }
  dijkstra(0);
  reps(i, n - 1) { cout << min_time[i] << endl; }
  return 0;
}