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

#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define MAXCOIN 2500LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long n, m, i, j, k, x, y, s, a, b, t, coin, id;
  cin >> n >> m >> s;

  vector<vector<tuple<long long, long long, long long>>> adj(n + 1);
  vector<long long> c(n + 1), d(n + 1);

  for (i = 0; i < m; i++) {
    cin >> x >> y >> a >> b;
    adj[x].push_back({y, a, b});
    adj[y].push_back({x, a, b});
  }

  for (i = 1; i <= n; i++)
    cin >> c[i] >> d[i];

  vector<vector<long long>> dp(
      n + 1,
      vector<long long>(MAXCOIN + 1,
                        (1LL << 60))); // dp[city][silve coins] = shortest time
  s = min(s, MAXCOIN);
  dp[1][s] = 0;
  priority_queue<tuple<long long, long long, long long>>
      pq; // <-time, id, coin>
  pq.push({0, 1, s});

  while (!pq.empty()) {
    tie(t, id, coin) = pq.top();
    t = -t;
    pq.pop();
    if (dp[id][coin] != t)
      continue;

    // exchange
    if (dp[id][min(MAXCOIN, coin + c[id])] > t + d[id]) {
      dp[id][min(MAXCOIN, coin + c[id])] = t + d[id];
      pq.push({-t - d[id], id, min(MAXCOIN, coin + c[id])});
    }

    // use it to go somewhere
    for (auto p : adj[id]) {
      tie(x, a, b) = p;

      if (coin < a)
        continue;

      if (t + b < dp[x][coin - a]) {
        dp[x][coin - a] = t + b;
        pq.push({-t - b, x, coin - a});
      }
    }
  }

  vector<long long> ans(n + 1, (1LL << 60));
  for (i = 2; i <= n; i++) {
    for (j = 0; j <= MAXCOIN; j++)
      ans[i] = min(ans[i], dp[i][j]);
  }

  for (i = 2; i <= n; i++)
    cout << ans[i] << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define MAXCOIN 2500LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long n, m, i, j, k, x, y, s, a, b, t, coin, id;
  cin >> n >> m >> s;

  vector<vector<tuple<long long, long long, long long>>> adj(n + 1);
  vector<long long> c(n + 1), d(n + 1);

  for (i = 0; i < m; i++) {
    cin >> x >> y >> a >> b;
    adj[x].push_back({y, a, b});
    adj[y].push_back({x, a, b});
  }

  for (i = 1; i <= n; i++)
    cin >> c[i] >> d[i];

  vector<vector<long long>> dp(
      n + 1,
      vector<long long>(MAXCOIN + 1,
                        (1LL << 60))); // dp[city][silve coins] = shortest time
  dp[1][s] = 0;
  priority_queue<tuple<long long, long long, long long>>
      pq; // <-time, id, coin>
  pq.push({0, 1, s});

  while (!pq.empty()) {
    tie(t, id, coin) = pq.top();
    t = -t;
    pq.pop();
    if (dp[id][coin] != t)
      continue;

    // exchange
    if (dp[id][min(MAXCOIN, coin + c[id])] > t + d[id]) {
      dp[id][min(MAXCOIN, coin + c[id])] = t + d[id];
      pq.push({-t - d[id], id, min(MAXCOIN, coin + c[id])});
    }

    // use it to go somewhere
    for (auto p : adj[id]) {
      tie(x, a, b) = p;

      if (coin < a)
        continue;

      if (t + b < dp[x][coin - a]) {
        dp[x][coin - a] = t + b;
        pq.push({-t - b, x, coin - a});
      }
    }
  }

  vector<long long> ans(n + 1, (1LL << 60));
  for (i = 2; i <= n; i++) {
    for (j = 0; j <= MAXCOIN; j++)
      ans[i] = min(ans[i], dp[i][j]);
  }

  for (i = 2; i <= n; i++)
    cout << ans[i] << "\\n";

  return 0;
}