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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct Edge {
  int to, cost, time;
  Edge(int to_, int cost_, int time_) : to(to_), cost(cost_), time(time_){};
};

struct Vertex {
  int silver, time_per_gold;
  Vertex() = default;
  Vertex(int silver_, int time_per_gold_)
      : silver(silver_), time_per_gold(time_per_gold_){};
};

struct Data {
  int vertex, money;
  long long sum_time;
  Data(int vertex_, int money_, long long sum_time_)
      : vertex(vertex_), money(money_), sum_time(sum_time_){};
  bool operator<(const Data &rhs) const & { return sum_time > rhs.sum_time; }
};

int main() {
  const long long INF = 1e18;
  const int MAX_V = 50;
  const int MAX_MONEY = 50 * 50 + 5;

  int numv, nume, money;
  cin >> numv >> nume >> money;

  money = min(MAX_MONEY, money);

  vector<vector<Edge>> edges(numv);
  vector<Vertex> verticies(numv);

  for (int i = 0; i < nume; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    edges[u].emplace_back(v, a, b);
    edges[v].emplace_back(u, a, b);
  }

  for (int i = 0; i < numv; i++) {
    int c, d;
    cin >> c >> d;
    verticies[i].silver = c;
    verticies[i].time_per_gold = d;
  }

  vector<vector<long long>> dp(MAX_V, vector<long long>(MAX_MONEY + 10, INF));
  priority_queue<Data> q;

  auto push = [&](int vertex_, int money_, long long sum_time) {
    if (money_ < 0)
      return;
    if (dp[vertex_][money_] <= sum_time)
      return;
    dp[vertex_][money_] = sum_time;
    q.emplace(vertex_, money_, sum_time);
  };

  push(0, money, 0);
  while (!q.empty()) {
    auto tempdata = q.top();
    q.pop();

    int tempv = tempdata.vertex;
    int tempmoney = tempdata.money;
    long long tempsum_time = tempdata.sum_time;

    if (dp[tempv][tempmoney] != tempsum_time)
      continue;

    push(tempv, min(verticies[tempv].silver + tempmoney, MAX_MONEY),
         tempsum_time + verticies[tempv].time_per_gold);

    for (const auto &e : edges[tempv]) {
      push(e.to, tempmoney - e.cost, tempsum_time + e.time);
    }
  }

  for (int i = 1; i < numv; i++) {
    long long ans = INF;
    for (int j = 0; j < MAX_MONEY + 10; j++) {
      ans = min(dp[i][j], ans);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct Edge {
  int to, cost, time;
  Edge(int to_, int cost_, int time_) : to(to_), cost(cost_), time(time_){};
};

struct Vertex {
  int silver, time_per_gold;
  Vertex() = default;
  Vertex(int silver_, int time_per_gold_)
      : silver(silver_), time_per_gold(time_per_gold_){};
};

struct Data {
  int vertex, money;
  long long sum_time;
  Data(int vertex_, int money_, long long sum_time_)
      : vertex(vertex_), money(money_), sum_time(sum_time_){};
  bool operator<(const Data &rhs) const & { return sum_time > rhs.sum_time; }
};

int main() {
  const long long INF = __LONG_LONG_MAX__;
  const int MAX_V = 50;
  const int MAX_MONEY = 50 * 50 + 5;

  int numv, nume, money;
  cin >> numv >> nume >> money;

  money = min(MAX_MONEY, money);

  vector<vector<Edge>> edges(numv);
  vector<Vertex> verticies(numv);

  for (int i = 0; i < nume; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    edges[u].emplace_back(v, a, b);
    edges[v].emplace_back(u, a, b);
  }

  for (int i = 0; i < numv; i++) {
    int c, d;
    cin >> c >> d;
    verticies[i].silver = c;
    verticies[i].time_per_gold = d;
  }

  long long dp[MAX_V][MAX_MONEY];
  for (auto &ddp : dp) {
    for (auto &dddp : ddp) {
      dddp = INF;
    }
  }

  priority_queue<Data> q;

  auto push = [&](int vertex_, int money_, long long sum_time) {
    if (money_ < 0)
      return;
    if (dp[vertex_][money_] <= sum_time)
      return;
    dp[vertex_][money_] = sum_time;
    q.emplace(vertex_, money_, sum_time);
  };

  push(0, money, 0);
  while (!q.empty()) {
    auto tempdata = q.top();
    q.pop();

    int tempv = tempdata.vertex;
    int tempmoney = tempdata.money;
    long long tempsum_time = tempdata.sum_time;

    if (dp[tempv][tempmoney] != tempsum_time)
      continue;

    push(tempv, verticies[tempv].silver + min(tempmoney, MAX_MONEY),
         tempsum_time + verticies[tempv].time_per_gold);

    for (const auto &e : edges[tempv]) {
      push(e.to, tempmoney - e.cost, tempsum_time + e.time);
    }
  }

  for (int i = 1; i < numv; i++) {
    long long ans = INF;
    for (int j = 0; j < MAX_MONEY; j++) {
      ans = min(dp[i][j], ans);
    }
    cout << ans << endl;
  }

  return 0;
}