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

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

ll nodid(ll node, ll money, ll maxmoney) {
  return node * (maxmoney + 1) + money;
}

void print() { cout << endl; }
template <typename Head, typename... Tail> void print(Head head, Tail... tail) {
  int size = sizeof...(Tail);
  cout << head;
  if (size > 0) {
    cout << " ";
  }
  print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
  cout << head;
  print0(tail...);
}

struct edge {
  ll u;
  ll v;
  ll cost;
};
bool operator<=(const edge &lhs, const edge &rhs) {
  return lhs.cost <= rhs.cost;
}
bool operator<(const edge &lhs, const edge &rhs) { return lhs.cost < rhs.cost; }
bool operator>=(const edge &lhs, const edge &rhs) {
  return lhs.cost >= rhs.cost;
}
bool operator>(const edge &lhs, const edge &rhs) { return lhs.cost > rhs.cost; }
bool operator==(const edge &lhs, const edge &rhs) {
  return lhs.cost == rhs.cost;
}
bool operator!=(const edge &lhs, const edge &rhs) {
  return lhs.cost != rhs.cost;
}

void dijkstra(ll start, vector<vector<edge>> &edgemap, vector<ll> &min_cost) {
  vector<bool> done(edgemap.size(), false);
  priority_queue<edge, vector<edge>, greater<edge>> pq;

  pq.push(edge{u : -1, v : start, cost : 0});
  while (!pq.empty()) {
    edge e = pq.top();
    pq.pop();
    if (done[e.v]) {
      continue;
    }
    done[e.v] = true;
    min_cost[e.v] = e.cost;
    for (auto next_e : edgemap[e.v]) {
      if (!done[next_e.v]) {
        edge total_next_e = next_e;
        total_next_e.cost = e.cost + next_e.cost;
        pq.push(total_next_e);
      }
    }
  }
}

struct edgtime {
  ll u;
  ll v;
  ll money;
  ll time;
};
int main() {
  ll N, M, S;
  cin >> N >> M >> S;
  ll maxmoney = (N + 1) * 50;

  vector<edgtime> edgtimes(M);
  for (ll i = 0; i < M; i++) {
    edgtime ee;
    cin >> ee.u >> ee.v >> ee.money >> ee.time;
    edgtimes[i] = ee;
  }

  vector<ll> C(N + 1);
  vector<ll> D(N + 1);
  for (ll i = 1; i <= N; i++) {
    cin >> C[i] >> D[i];
  }
  vector<vector<edge>> edgemap((maxmoney + 1) * (N + 1) + 1);

  for (ll i = 1; i <= N; i++) {
    for (ll money = 0; money <= maxmoney; money++) {
      ll nextmoney = min(money + C[i], maxmoney);
      auto src = nodid(i, money, maxmoney);
      auto dest = nodid(i, nextmoney, maxmoney);
      edgemap[src].push_back({src, dest, D[i]});
    }
  }
  for (auto et : edgtimes) {
    for (ll money = 0; money <= maxmoney; money++) {
      ll nextmoney = money - et.money;
      if (nextmoney >= 0) {
        ll src_uv = nodid(et.u, money, maxmoney);
        ll dest_uv = nodid(et.v, nextmoney, maxmoney);

        ll src_vu = nodid(et.v, money, maxmoney);
        ll dest_vu = nodid(et.u, nextmoney, maxmoney);

        edgemap[src_uv].push_back({src_uv, dest_uv, et.time});
        edgemap[src_vu].push_back({src_vu, dest_vu, et.time});
      }
    }
  }

  ll s = min(S, maxmoney);
  vector<ll> min_cost((maxmoney + 1) * (N + 1) + 1, INF);
  dijkstra(nodid(1, s, maxmoney), edgemap, min_cost);

  for (ll t = 2; t <= N; t++) {
    ll mc = INF;
    for (ll money = 0; money <= maxmoney; money++) {
      mc = min(min_cost[nodid(t, money, maxmoney)], mc);
    }
    print(mc);
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

ll divceil(ll numer, ll denom) {
  if (numer % denom == 0) {
    return numer / denom;
  } else {
    return 1L + numer / denom;
  }
}

void print() { cout << endl; }
template <typename Head, typename... Tail> void print(Head head, Tail... tail) {
  int size = sizeof...(Tail);
  cout << head;
  if (size > 0) {
    cout << " ";
  }
  print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
  cout << head;
  print0(tail...);
}

struct edge {
  ll u;
  ll v;
  ll money;
  ll time;
};
bool operator<=(const edge &lhs, const edge &rhs) {
  return lhs.time <= rhs.time;
}
bool operator<(const edge &lhs, const edge &rhs) { return lhs.time < rhs.time; }
bool operator>=(const edge &lhs, const edge &rhs) {
  return lhs.time >= rhs.time;
}
bool operator>(const edge &lhs, const edge &rhs) { return lhs.time > rhs.time; }
bool operator==(const edge &lhs, const edge &rhs) {
  return lhs.time == rhs.time;
}
bool operator!=(const edge &lhs, const edge &rhs) {
  return lhs.time != rhs.time;
}
ll dijkstra(ll start, ll end, vector<vector<edge>> &edgemap,
            vector<ll> &min_time, vector<edge> &minroute) {
  vector<bool> done(edgemap.size(), false);
  priority_queue<edge, vector<edge>, greater<edge>> pq;

  pq.push(edge{u : -1, v : start, time : 0});
  while (!pq.empty()) {
    edge e = pq.top();
    pq.pop();
    if (done[e.v]) {
      continue;
    }
    done[e.v] = true;
    min_time[e.v] = e.time;
    minroute.push_back(e);
    if (e.v == end) {
      return min_time[e.v];
      break;
    }
    for (auto next_e : edgemap[e.v]) {
      if (!done[next_e.v]) {
        edge total_next_e = next_e;
        total_next_e.time = e.time + next_e.time;
        pq.push(total_next_e);
      }
    }
  }
}

struct cp {
  ll money;
  ll time;
  double rate;
};
int main() {
  ll N, M, S;
  cin >> N >> M >> S;

  vector<vector<edge>> edgemap(N + 1);

  for (ll i = 0; i < M; i++) {
    edge e;
    cin >> e.u >> e.v >> e.money >> e.time;
    edge ee = {e.v, e.u, e.money, e.time};
    edgemap[e.u].push_back(e);
    edgemap[ee.u].push_back(ee);
  }

  vector<cp> cps(N + 1);
  for (ll i = 1; i <= N; i++) {
    ll c, d;
    cin >> c >> d;
    cps[i] = {c, d, 1.0 * c / d};
  }

  vector<vector<ll>> mintimes(51, vector<ll>(51, INF));
  vector<vector<vector<edge>>> minroutes(51, vector<vector<edge>>(51));
  for (ll i = 1; i <= N; i++) {
    for (ll j = i + 1; j <= N; j++) {
      vector<ll> mintim(51, INF);
      ll mintime = dijkstra(i, j, edgemap, mintim, minroutes[i][j]);
      mintimes[i][j] = mintime;
      mintimes[j][i] = mintime;
      minroutes[j][i] = minroutes[i][j];
    }
  }

  for (ll t = 2; t <= N; t++) {
    ll minmintime = INF;
    for (ll mid = 2; mid <= N; mid++) {
      ll time = 0;
      ll money = 0;
      cp maxrate = {1, 1, -1.0};
      for (auto e : minroutes[1][mid]) {
        time += e.time;
        money += e.money;
      }
      for (auto e : minroutes[mid][t]) {
        time += e.time;
        money += e.money;
      }
      ll cmoney = -money + S;

      ll mintime = INF;
      if (cmoney > 0) {
        for (auto e : minroutes[1][mid]) {
          mintime = min(mintime,
                        time + divceil(cmoney, cps[e.u].money) * cps[e.u].time);
          mintime = min(mintime,
                        time + divceil(cmoney, cps[e.v].money) * cps[e.v].time);
        }
        for (auto e : minroutes[mid][t]) {
          mintime = min(mintime,
                        time + divceil(cmoney, cps[e.u].money) * cps[e.u].time);
          mintime = min(mintime,
                        time + divceil(cmoney, cps[e.v].money) * cps[e.v].time);
        }
      } else {
        mintime = time;
      }
      minmintime = min(mintime, minmintime);
    }
    print(minmintime);
  }
}