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

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

#define M 1000000007
#define MM 998244353
#define ll long long
#define pb push_back
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define sz(a) (ll) a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
// RNG based on mersenne_twister
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b, ll e, ll m) {
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
ll power(ll b, ll e) {
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
template <typename T, typename U> static inline void amin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static inline void amax(T &x, U y) {
  if (x < y)
    x = y;
}

vector<pair<ll, pair<ll, ll>>> ed[55];
ll c[60], d[60];
map<pair<ll, ll>, ll> hh;
ll dis[250200];
vector<pair<ll, ll>> v[250200];
ll s;
void djikstra() {
  set<pair<ll, ll>> ss;
  ss.insert({0, hh[{1, s}]});
  dis[hh[{1, s}]] = 0;
  while (!ss.empty()) {
    pair<ll, ll> p = *ss.begin();
    ss.erase(*ss.begin());
    ll u = p.S;
    for (auto j : v[p.S]) {
      ll w = j.F;
      if (dis[j.S] > dis[u] + w) {
        if (dis[j.S] != INF)
          ss.erase({dis[j.S], j.S});
        dis[j.S] = dis[u] + w;
        ss.insert({dis[j.S], j.S});
      }
    }
  }
}
int _runtimeTerror_() {
  ll n, m, i, j;
  ll k = 1;
  cin >> n >> m >> s;
  s = min(s, 5000LL);
  for (i = 0; i < m; ++i) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    ed[u].pb({v, {a, b}});
    ed[v].pb({u, {a, b}});
  }
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 5000; ++j)
      hh[{i, j}] = k++;
  }
  for (i = 1; i <= 250199; ++i)
    dis[i] = INF;
  for (i = 1; i <= n; ++i)
    cin >> c[i] >> d[i];
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 5000 - c[i]; ++j) {
      v[hh[{i, j}]].pb({d[i], hh[{i, j + c[i]}]});
    }
    for (j = 0; j <= 5000; ++j) {
      for (auto k : ed[i]) {
        if (k.S.F <= j) {
          v[hh[{i, j}]].pb({k.S.S, hh[{k.F, j - k.S.F}]});
        }
      }
    }
  }
  djikstra();
  ll ans[n + 1];
  for (i = 1; i <= n; ++i) {
    ans[i] = INF;
    for (j = 0; j <= 5000; ++j)
      amin(ans[i], dis[hh[{i, j}]]);
  }
  for (i = 2; i <= n; ++i)
    cout << ans[i] << endl;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef runSieve
  sieve();
#endif
#ifdef NCR
  initialize();
#endif
  int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--)
    _runtimeTerror_();
  cerr << "\\n" << _time_;
  return 0;
}


Error: 0

0.160862

Fixed submission:

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

#define M 1000000007
#define MM 998244353
#define ll long long
#define pb push_back
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define sz(a) (ll) a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
// RNG based on mersenne_twister
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b, ll e, ll m) {
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
ll power(ll b, ll e) {
  if (e == 0)
    return 1;
  if (e & 1)
    return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
template <typename T, typename U> static inline void amin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static inline void amax(T &x, U y) {
  if (x < y)
    x = y;
}

const int N = 500005;
vector<pair<ll, pair<ll, ll>>> ed[55];
ll c[60], d[60];
map<pair<ll, ll>, ll> hh;
ll dis[250004];
vector<pair<ll, ll>> v[250004];
ll s;
void djikstra() {
  set<pair<ll, ll>> ss;
  ss.insert({0, hh[{1, s}]});
  dis[hh[{1, s}]] = 0;
  while (!ss.empty()) {
    pair<ll, ll> p = *ss.begin();
    ss.erase(*ss.begin());
    ll u = p.S;
    for (auto j : v[p.S]) {
      ll w = j.F;
      if (dis[j.S] > dis[u] + w) {
        if (dis[j.S] != INF)
          ss.erase({dis[j.S], j.S});
        dis[j.S] = dis[u] + w;
        ss.insert({dis[j.S], j.S});
      }
    }
  }
}
int _runtimeTerror_() {
  ll n, m, i, j;
  ll k = 1;
  cin >> n >> m >> s;
  s = min(s, 5000LL);
  for (i = 0; i < m; ++i) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    ed[u].pb({v, {a, b}});
    ed[v].pb({u, {a, b}});
  }
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 5000; ++j)
      hh[{i, j}] = k++;
  }
  for (i = 1; i <= 250000; ++i)
    dis[i] = INF;
  for (i = 1; i <= n; ++i)
    cin >> c[i] >> d[i];
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= 5000 - c[i]; ++j) {
      v[hh[{i, j}]].pb({d[i], hh[{i, j + c[i]}]});
    }
    for (j = 0; j <= 5000; ++j) {
      for (auto k : ed[i]) {
        if (k.S.F <= j) {
          v[hh[{i, j}]].pb({k.S.S, hh[{k.F, j - k.S.F}]});
        }
      }
    }
  }
  djikstra();
  ll ans[n + 1];
  for (i = 1; i <= n; ++i) {
    ans[i] = INF;
    for (j = 0; j <= 5000; ++j)
      amin(ans[i], dis[hh[{i, j}]]);
  }
  for (i = 2; i <= n; ++i)
    cout << ans[i] << endl;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef runSieve
  sieve();
#endif
#ifdef NCR
  initialize();
#endif
  int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--)
    _runtimeTerror_();
  cerr << "\\n" << _time_;
  return 0;
}