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

#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

const int inf = 1e18;
const int maxN = 50 + 1;
const int maxMoney = maxN * 100 + 1234;

vector<pair<int, pair<int, int>>> g[maxN][maxMoney];

int convert(int i, int j) { return i * maxMoney + j; }

pair<int, int> convert_back(int num) {
  return {num / maxMoney, num % maxMoney};
}

void solve() {
  int n, m, s;
  cin >> n >> m >> s;
  if (s > maxMoney)
    s = maxMoney - 1;
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = 0; j < maxMoney; ++j) {
      if (j >= a) {
        g[u][j].push_back({v, {a, b}});
        g[v][j].push_back({u, {a, b}});
      }
    }
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i] >> d[i];
  }

  vector<int> D(10 * maxN * maxMoney, inf);
  set<pair<int, int>> S;
  vector<int> usd(10 * maxN * maxMoney, 0);
  int start = convert(0, s);
  D[start] = 0;
  S.insert({D[start], start});
  while (!S.empty()) {
    auto it = S.begin();
    int num = (*it).second;
    usd[num] = 1;
    S.erase(it);
    pair<int, int> con = convert_back(num);
    int v = con.first;
    int mon = con.second;
    // try to make more money...
    if (mon + c[v] < maxMoney) {
      if (D[num + c[v]] > D[num] + d[v]) {
        S.erase({D[num + c[v]], num + c[v]});
        D[num + c[v]] = D[num] + d[v];
        S.insert({D[num + c[v]], num + c[v]});
      }
    }
    // try to go somewhere...
    for (auto u : g[v][mon]) {
      int nv = u.first;
      int nm = mon - u.second.first;
      int delta = u.second.second;
      int nvert = convert(nv, nm);
      if (!usd[nvert] && D[nvert] > D[num] + delta) {
        S.erase({D[nvert], nvert});
        D[nvert] = D[num] + delta;
        S.insert({D[nvert], nvert});
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int ans = inf;
    for (int j = 0; j < maxMoney; ++j) {
      ans = min(ans, D[convert(i, j)]);
    }
    cout << ans << '\\n';
  }
}

signed main() {
#ifdef lolipop
  freopen("input.txt", "r", stdin);
#else
  fastio();
#endif

  int T = 1;
  //    cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

const int inf = 1e18;
const int maxN = 50 + 1;
const int maxMoney = maxN * 100 + 123;

vector<pair<int, pair<int, int>>> g[maxN][maxMoney];

int convert(int i, int j) { return i * maxMoney + j; }

pair<int, int> convert_back(int num) {
  return {num / maxMoney, num % maxMoney};
}

void solve() {
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 0; i < m; ++i) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = 0; j < maxMoney; ++j) {
      if (j >= a) {
        g[u][j].push_back({v, {a, b}});
        g[v][j].push_back({u, {a, b}});
      }
    }
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i] >> d[i];
  }

  vector<int> D(10 * maxN * maxMoney, inf);
  set<pair<int, int>> S;
  vector<int> usd(10 * maxN * maxMoney, 0);
  int start = convert(0, s);
  D[start] = 0;
  S.insert({D[start], start});
  while (!S.empty()) {
    auto it = S.begin();
    int num = (*it).second;
    usd[num] = 1;
    S.erase(it);
    pair<int, int> con = convert_back(num);
    int v = con.first;
    int mon = con.second;
    // try to make more money...
    if (mon + c[v] < maxMoney) {
      if (D[num + c[v]] > D[num] + d[v]) {
        S.erase({D[num + c[v]], num + c[v]});
        D[num + c[v]] = D[num] + d[v];
        S.insert({D[num + c[v]], num + c[v]});
      }
    }
    // try to go somewhere...
    for (auto u : g[v][mon]) {
      int nv = u.first;
      int nm = mon - u.second.first;
      int delta = u.second.second;
      int nvert = convert(nv, nm);
      if (!usd[nvert] && D[nvert] > D[num] + delta) {
        S.erase({D[nvert], nvert});
        D[nvert] = D[num] + delta;
        S.insert({D[nvert], nvert});
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int ans = inf;
    for (int j = 0; j < maxMoney; ++j) {
      ans = min(ans, D[convert(i, j)]);
    }
    cout << ans << '\\n';
  }
}

signed main() {
#ifdef lolipop
  freopen("input.txt", "r", stdin);
#else
  fastio();
#endif

  int T = 1;
  //    cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}