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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_V = 50;
const int MAX_S = MAX_V * 50 + 5;
const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x) : v(v), s(s), x(x) {}
  bool operator<(const Data &a) const { return x > a.x; }
};

vector<Edge> g[MAX_V];
ll dist[MAX_V][MAX_S + 5];

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u;
    --v;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  rep(i, n) rep(j, MAX_S + 5) dist[i][j] = INF;
  s = min(s, MAX_S);
  priority_queue<Data> q;
  auto push = [&](int v, int s, ll x) {
    if (s < 0)
      return;
    if (dist[v][s] <= x)
      return;
    dist[v][s] = x;
    q.emplace(v, s, x);
  };
  vector<int> c(n), d(n);
  rep(i, n) cin >> c[i] >> d[i];
  push(0, s, 0);
  while (!q.empty()) {
    Data hoge = q.top();
    q.pop();
    int v = hoge.v, s = hoge.s;
    ll x = hoge.x;
    if (dist[v][s] != x)
      continue;
    {
      int ns = min(s + c[v], MAX_S);
      push(v, ns, x + d[v]);
    }
    for (Edge e : g[v]) {
      push(e.to, s - e.a, x + e.b);
    }
  }
  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    rep(j, MAX_S + 5) { ans = min(ans, dist[i][j]); }
    cout << ans << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

const ll INF = 1L << 40;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};

struct Data {
  int v, s;
  ll time;
  Data(int v, int s, ll time) : v(v), s(s), time(time){};
  bool operator<(const Data &a) const { return time > a.time; }
};

const int MAX_V = 50;
const int MAX_S = MAX_V * 50 + 5;

int main() {
  int n, m, have_s;
  cin >> n >> m >> have_s;
  vector<Edge> g[MAX_V];
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    int a, b;
    cin >> a >> b;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; ++i)
    cin >> c[i] >> d[i];
  ll dp[MAX_V][MAX_S];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < MAX_S + 5; ++j) {
      dp[i][j] = INF;
    }
  }

  priority_queue<Data> q;
  auto push = [&](int v, int s, ll time) {
    if (s < 0)
      return;
    if (dp[v][s] <= time)
      return;
    dp[v][s] = time;
    q.emplace(v, s, time);
  };
  have_s = min(have_s, MAX_S);
  push(0, have_s, 0);
  while (!q.empty()) {
    Data tmp = q.top();
    q.pop();
    if (tmp.time != dp[tmp.v][tmp.s])
      continue;

    int ns = min(tmp.s + c[tmp.v], MAX_S);
    push(tmp.v, ns, tmp.time + d[tmp.v]);

    for (Edge e : g[tmp.v]) {
      push(e.to, tmp.s - e.a, tmp.time + e.b);
    }
  }

  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    for (int j = 0; j <= MAX_S + 5; ++j) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}