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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef tuple<ll, ll, ll> T;

const ll inf = 1e18;
const ll MAX = 2500;
ll N, S;
vector<pair<ll, pair<ll, ll>>> g[100];
ll c[100], d[100];

void solve(int x) {
  if (S >= MAX)
    S = MAX;
  vector<vector<ll>> dp(N + 1, vector<ll>(MAX + 1, inf));
  priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>,
                 greater<pair<ll, pair<ll, ll>>>>
      que;
  que.push({0, {x, S}});
  dp[0][S] = 0;
  while (!que.empty()) {
    pair<ll, pair<ll, ll>> p = que.top();
    que.pop();
    ll time = p.first;
    ll u = p.second.first;
    ll cost = p.second.second;
    if (time > dp[u][cost])
      continue;
    if (cost + c[u] <= MAX) {
      ll n_cost = cost + c[u];
      ll n_time = time + d[u];
      if (dp[u][n_cost] > n_time) {
        dp[u][n_cost] = n_time;
        que.push({n_time, {u, n_cost}});
      }
    }
    for (auto tmp : g[u]) {
      ll v = tmp.first;
      ll a = tmp.second.first;
      ll b = tmp.second.second;
      ll n_cost = cost - a;
      if (n_cost < 0)
        continue;
      ll n_time = time + b;
      if (dp[v][n_cost] > n_time) {
        dp[v][n_cost] = n_time;
        que.push({n_time, {v, n_cost}});
      }
    }
  }

  for (int i = 1; i < N; i++) {
    ll ans = inf;
    for (int j = 0; j <= MAX; j++) {
      ans = min(dp[i][j], ans);
    }
    cout << ans << endl;
  }
}

int main() {
  ll M;
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    ll a, b;
    cin >> a >> b;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }
  for (int i = 0; i < N; i++) {
    cin >> c[i] >> d[i];
  }
  solve(0);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef tuple<ll, ll, ll> T;

const ll inf = 1e18;
const ll MAX = 2500;
ll N, S;
vector<pair<ll, pair<ll, ll>>> g[100];
ll c[100], d[100];

void solve(int x) {
  vector<vector<ll>> dp(N + 1, vector<ll>(MAX + 1, inf));
  priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>,
                 greater<pair<ll, pair<ll, ll>>>>
      que;
  que.push({0, {x, S}});
  dp[0][S] = 0;
  while (!que.empty()) {
    pair<ll, pair<ll, ll>> p = que.top();
    que.pop();
    ll time = p.first;
    ll u = p.second.first;
    ll cost = p.second.second;
    if (time > dp[u][cost])
      continue;
    if (cost + c[u] <= MAX) {
      ll n_cost = cost + c[u];
      ll n_time = time + d[u];
      if (dp[u][n_cost] > n_time) {
        dp[u][n_cost] = n_time;
        que.push({n_time, {u, n_cost}});
      }
    }
    for (auto tmp : g[u]) {
      ll v = tmp.first;
      ll a = tmp.second.first;
      ll b = tmp.second.second;
      ll n_cost = cost - a;
      if (n_cost < 0)
        continue;
      ll n_time = time + b;
      if (dp[v][n_cost] > n_time) {
        dp[v][n_cost] = n_time;
        que.push({n_time, {v, n_cost}});
      }
    }
  }

  for (int i = 1; i < N; i++) {
    ll ans = inf;
    for (int j = 0; j <= MAX; j++) {
      ans = min(dp[i][j], ans);
    }
    cout << ans << endl;
  }
}

int main() {
  ll M;
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    ll a, b;
    cin >> a >> b;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }
  for (int i = 0; i < N; i++) {
    cin >> c[i] >> d[i];
  }
  solve(0);
}