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

#include <bits/stdc++.h>

#define int long long
#define uint unsigned int
#define ld long double
#define showoff                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a, int n) {
  a %= mod;
  if (n == 1)
    return a;
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
  return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;

int inverse(int x) {
  return power(x, mod - 2) % mod; // little fermat....
}
int n, m, ic, a[110], b[110], c[60], d[60], dp[55][3005], ans[60];
vector<pii> adj[60];

void solve() {
  cin >> n >> m >> ic;
  ic = min(ic, 2500LL);
  FOR(i, 1, m + 1) {
    int u, v;
    cin >> u >> v >> a[i] >> b[i];
    adj[u].pb({v, i});
    adj[v].pb({u, i});
  }
  FOR(i, 1, n + 1) cin >> c[i] >> d[i];
  FOR(i, 1, n + 1) {
    if (i > 1)
      ans[i] = inf;
    FOR(j, 0, 3000) dp[i][j] = inf;
  }
  set<pair<int, pii>> s;
  s.insert({0, {1, ic}});
  while (!s.empty()) {
    int tim = (*s.begin()).f, x = (*s.begin()).se.f, coins = (*s.begin()).se.se;
    s.erase(s.begin());
    if (dp[x][coins] <= tim)
      continue;
    dp[x][coins] = tim;
    if (coins < 2500)
      s.insert({tim + d[x], {x, coins + c[x]}});
    for (auto &y : adj[x]) {
      if (coins >= a[y.se] && dp[y.f][coins - a[y.se]] == inf) {
        s.insert({tim + b[y.se], {y.f, coins - a[y.se]}});
      }
    }
  }
  FOR(i, 2, n + 1) { FOR(j, 0, 2500) ans[i] = min(ans[i], dp[i][j]); }
  FOR(i, 2, n + 1) cout << ans[i] << "\\n";
}

signed main() {
  // showoff;
  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define int long long
#define uint unsigned int
#define ld long double
#define showoff                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define f first
#define se second
#define maxn 200005
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vector<int>, greater<int>>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a, int n) {
  a %= mod;
  if (n == 1)
    return a;
  if (n == 0)
    return 1;
  if (n % 2)
    return (a * (power((a * a) % mod, n / 2) % mod)) % mod;
  return power((a * a) % mod, n / 2) % mod;
}
const int inf = (int)1e18;

int inverse(int x) {
  return power(x, mod - 2) % mod; // little fermat....
}
int n, m, ic, a[110], b[110], c[60], d[60], dp[55][6000], ans[60];
vector<pii> adj[60];

void solve() {
  cin >> n >> m >> ic;
  FOR(i, 1, m + 1) {
    int u, v;
    cin >> u >> v >> a[i] >> b[i];
    adj[u].pb({v, i});
    adj[v].pb({u, i});
  }
  FOR(i, 1, n + 1) cin >> c[i] >> d[i];
  FOR(i, 1, n + 1) {
    if (i > 1)
      ans[i] = inf;
    FOR(j, 0, 3000) dp[i][j] = inf;
  }
  FOR(i, 0, ic + 1) dp[1][i] = 0;
  set<int> s;
  s.insert(1);
  while (!s.empty()) {
    int x = (*s.begin());
    s.erase(s.begin());
    for (auto &y : adj[x]) {
      bool fo = 0;
      FOR(i, 0, 3000) {
        FOR(j, 0, 3000) {
          if (dp[x][j] == inf)
            break;
          int cost = dp[x][j] +
                     max(0LL, ((i + a[y.se] - j) * d[x] + c[x] - 1) / c[x]) +
                     b[y.se];
          if (cost >= dp[y.f][i])
            continue;
          fo = 1;
          dp[y.f][i] = cost;
          ans[y.f] = min(ans[y.f], cost);
        }
      }
      if (fo)
        s.insert(y.f);
    }
  }
  FOR(i, 2, n + 1) cout << ans[i] << "\\n";
}

signed main() {
  // showoff;
  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...