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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

ll n, m, s;
ll a[110], b[110];
ll c[55], d[55];

vector<pll> adj[55];
vector<pll> adjstate[55 * 2500];

ll conv(ll v, ll s) { return v * 2500ll + s; }

vl dijkstra(int s) {
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  vector<ll> dist(55 * 2500, 1e18);
  dist[s] = 0;
  pq.push(mp(dist[s], s));
  while (!pq.empty()) {
    auto tmp = pq.top();
    pq.pop();
    ll from = tmp.second;
    ll d = tmp.first;
    if (dist[from] < d)
      continue;
    for (auto p : adjstate[from]) {
      ll to = p.first;
      ll cost = p.second;
      if (dist[to] > dist[from] + cost) {
        dist[to] = dist[from] + cost;
        pq.push(mp(dist[to], to));
      }
    }
  }
  return dist;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  rep(i, m) {
    ll u, v;
    cin >> u >> v >> a[i] >> b[i];
    u--, v--;
    adj[u].pb(mp(v, i));
    adj[v].pb(mp(u, i));
  }
  rep(i, n) cin >> c[i] >> d[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2500; j++) {
      int to = min(j + c[i], 2499ll);
      // exchanging currencies
      adjstate[conv(i, j)].pb(mp(conv(i, to), d[i]));

      for (auto p : adj[i]) {
        ll to = p.first;
        ll eid = p.second;
        if (j < a[eid])
          continue;
        // transit while paying b[i]
        adjstate[conv(i, j)].pb(mp(conv(to, j - a[eid]), b[eid]));
      }
    }
  }
  s = min(s, 2499ll);
  auto dist = dijkstra(conv(0, s));
  for (int i = 1; i < n; i++) {
    ll ans = 1e18;
    for (int j = 0; j < 2500; j++) {
      ans = min(ans, dist[conv(i, j)]);
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

ll n, m, s;
ll a[110], b[110];
ll c[55], d[55];

vector<pll> adj[55];
vector<pll> adjstate[55 * 2500];

ll conv(ll v, ll s) { return v * 2500ll + s; }

vl dijkstra(int s) {
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  vector<ll> dist(55 * 2500, 1e18);
  dist[s] = 0;
  pq.push(mp(dist[s], s));
  while (!pq.empty()) {
    auto tmp = pq.top();
    pq.pop();
    ll from = tmp.second;
    ll d = tmp.first;
    if (dist[from] < d)
      continue;
    for (auto p : adjstate[from]) {
      ll to = p.first;
      ll cost = p.second;
      if (dist[to] > dist[from] + cost) {
        dist[to] = dist[from] + cost;
        pq.push(mp(dist[to], to));
      }
    }
  }
  return dist;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  rep(i, m) {
    ll u, v;
    cin >> u >> v >> a[i] >> b[i];
    u--, v--;
    adj[u].pb(mp(v, i));
    adj[v].pb(mp(u, i));
  }
  rep(i, n) cin >> c[i] >> d[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2499; j++) {
      int to = min(j + c[i], 2499ll);
      // exchanging currencies
      adjstate[conv(i, j)].pb(mp(conv(i, to), d[i]));

      for (auto p : adj[i]) {
        ll to = p.first;
        ll eid = p.second;
        if (j < a[eid])
          continue;
        // transit while paying b[i]
        adjstate[conv(i, j)].pb(mp(conv(to, j - a[eid]), b[eid]));
      }
    }
  }
  auto dist = dijkstra(conv(0, s));
  for (int i = 1; i < n; i++) {
    ll ans = 1e18;
    for (int j = 0; j < 2500; j++) {
      ans = min(ans, dist[conv(i, j)]);
    }
    cout << ans << endl;
  }
}