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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define N_MAX 50
#define A_MAX 5050
#define INF 1e18
#define stat(v, c) ((v)*A_MAX + (c))

struct edge {
  int to, cost;
};
vector<edge> adj[N_MAX * A_MAX];
ll dist[N_MAX * A_MAX];

//-------------------------------------------------

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    FOR(j, a, A_MAX - 1) {
      adj[stat(v, j)].pb({stat(u, j - a), b});
      adj[stat(u, j)].pb({stat(v, j - a), b});
    }
  }
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    rep(j, A_MAX) adj[stat(i, j)].pb({stat(i, min(j + c, A_MAX - 1)), d});
  }

  using P = pair<ll, int>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, stat(0, min(s, A_MAX - 1)));
  rep(i, N_MAX * A_MAX) dist[i] = INF;
  dist[stat(0, min(s, A_MAX - 1))] = 0;
  while (!que.empty()) {
    int v;
    ll cost;
    tie(cost, v) = que.top();
    que.pop();
    if (dist[v] < cost)
      continue;
    for (auto e : adj[v]) {
      if (dist[v] + e.cost < dist[e.to]) {
        dist[e.to] = dist[v] + e.cost;
        que.emplace(dist[e.to], e.to);
      }
    }
  }
  FOR(i, 1, n - 1) {
    ll ans = INF;
    rep(j, A_MAX) chmin(ans, dist[stat(i, j)]);
    cout << ans << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>

#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define N_MAX 50
#define A_MAX 5050
#define INF 1e18
#define stat(v, c) ((v)*A_MAX + (c))

struct edge {
  int to, cost;
};
vector<edge> adj[N_MAX * A_MAX * 2];
ll dist[N_MAX * A_MAX * 2];

//-------------------------------------------------

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    FOR(j, a, A_MAX - 1) {
      adj[stat(v, j)].pb({stat(u, j - a), b});
      adj[stat(u, j)].pb({stat(v, j - a), b});
    }
  }
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    rep(j, A_MAX - c) adj[stat(i, j)].pb({stat(i, j + c), d});
  }

  using P = pair<ll, int>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, stat(0, s));
  rep(i, N_MAX * A_MAX) dist[i] = INF;
  dist[stat(0, s)] = 0;
  while (!que.empty()) {
    int v;
    ll cost;
    tie(cost, v) = que.top();
    que.pop();
    if (dist[v] < cost)
      continue;
    for (auto e : adj[v]) {
      if (dist[v] + e.cost < dist[e.to]) {
        dist[e.to] = dist[v] + e.cost;
        que.emplace(dist[e.to], e.to);
      }
    }
  }
  FOR(i, 1, n - 1) {
    ll ans = INF;
    rep(j, A_MAX) chmin(ans, dist[stat(i, j)]);
    cout << ans << "\\n";
  }
  return 0;
}