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

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

const ll INF = 1e15;

struct edge {
  ll to;
  ll cost;
  ll time;
};

struct Data {
  ll node;
  ll cost;
  ll time;
  Data(ll node, ll cost, ll time) : node(node), cost(cost), time(time) {}
  bool operator<(const Data &data) const { return cost > data.cost; }
  bool operator>(const Data &data) const { return cost < data.cost; }
};

int main(void) {
  ll n, m, s;
  cin >> n >> m >> s;
  s = min(s, 50LL * 100);

  vector<vector<edge>> edges(n + m);
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edges[u].push_back({v, -a, b});
    edges[v].push_back({u, -a, b});
  }
  rep(i, n) {
    ll c, d;
    cin >> c >> d;
    edges[i].push_back({i, c, d});
  }
  vector<vector<ll>> dp(n, vector<ll>(50 * 101, INF));
  priority_queue<Data> q;
  q.emplace(0, s, 0);
  dp[0][s] = 0;
  while (q.size()) {
    auto t = q.top();
    q.pop();
    for (auto &e : edges[t.node]) {
      auto to = e.to;
      auto cost = t.cost + e.cost;
      cost = min(cost, 50LL * 100);
      auto time = t.time + e.time;
      if (cost < 0)
        continue;
      if (dp[to][cost] <= time)
        continue;
      dp[to][cost] = time;
      q.emplace(to, cost, time);
    }
  }
  vector<ll> r(n, INF);
  rep(i, n - 1) {
    rep(j, 50 * 101) { r[i + 1] = min(r[i + 1], dp[i + 1][j]); }
  }
  rep(i, n - 1) { cout << r[i + 1] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

const ll INF = 1e15;

struct edge {
  ll to;
  ll cost;
  ll time;
};

struct Data {
  ll node;
  ll cost;
  ll time;
  Data(ll node, ll cost, ll time) : node(node), cost(cost), time(time) {}
  bool operator<(const Data &data) const { return cost > data.cost; }
  bool operator>(const Data &data) const { return cost < data.cost; }
};

int main(void) {
  ll n, m, s;
  cin >> n >> m >> s;

  vector<vector<edge>> edges(n + m);
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edges[u].push_back({v, -a, b});
    edges[v].push_back({u, -a, b});
  }
  rep(i, n) {
    ll c, d;
    cin >> c >> d;
    edges[i].push_back({i, c, d});
  }
  vector<vector<ll>> dp(n, vector<ll>(50 * 101, INF));
  priority_queue<Data> q;
  q.emplace(0, s, 0);
  dp[0][s] = 0;
  while (q.size()) {
    auto t = q.top();
    q.pop();
    for (auto &e : edges[t.node]) {
      auto to = e.to;
      auto cost = t.cost + e.cost;
      cost = min(cost, 50LL * 100);
      auto time = t.time + e.time;
      if (cost < 0)
        continue;
      if (dp[to][cost] <= time)
        continue;
      dp[to][cost] = time;
      q.emplace(to, cost, time);
    }
  }
  vector<ll> r(n, INF);
  rep(i, n - 1) {
    rep(j, 50 * 101) { r[i + 1] = min(r[i + 1], dp[i + 1][j]); }
  }
  rep(i, n - 1) { cout << r[i + 1] << endl; }
  return 0;
}