Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pint pair<int, int>
#define vec vector<int>
#define vvec vector<vec>
#define pvec vector<vector<pint>>
#define tint tuple<int, int, int>
#define mt make_tuple

int n, m, s;
vvec to;
pvec cost;

const int inf = 1LL << 60;

int dp[60][3000];
// その状態までにかかる時間
int c[60], d[60];

bool chmin(int &a, int b) {
  if (a > b) {
    swap(a, b);
    return true;
  } else {
    return false;
  }
}

void Dijkstra(int a, int b) {

  dp[a][b] = 0;

  priority_queue<tint, vector<tint>, greater<tint>> Q;
  // {時間、位置、枚数}

  Q.push(mt(0, a, b));

  while (!Q.empty()) {

    auto p = Q.top();
    Q.pop();

    int time = get<0>(p);
    int pos = get<1>(p);
    int num = get<2>(p);

    if (time > dp[pos][num]) {
      continue;
    }

    for (int i = 0; i < (int)to[pos].size(); i++) {

      int length = cost[pos][i].second;
      int silver = cost[pos][i].first;

      int next = to[pos][i];

      int res = min(num + c[pos], 2999LL);

      int res2 = num - silver;

      if (chmin(dp[pos][res], dp[pos][num] + d[pos])) {
        Q.push(mt(dp[pos][res], pos, res));
      }

      if (res2 >= 0) {
        if (chmin(dp[next][res2], dp[pos][num] + length)) {
          Q.push(mt(dp[next][res2], next, res2));
        }
      }

    } // for-u
  }   // while-Q

  return;
}

signed main(void) {

  cin >> n >> m >> s;
  to.resize(n);
  cost.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    to[u].push_back(v);
    to[v].push_back(u);
    cost[u].push_back({a, b});
    cost[v].push_back({a, b});
  }

  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 3000; j++) {
      dp[i][j] = inf;
    }
  }

  Dijkstra(0, s);

  int ans = inf;

  for (int i = 1; i < n; i++) {
    int ans = inf;

    for (int j = 0; j < 3000; j++) {

      ans = min(ans, dp[i][j]);
    }

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pint pair<int, int>
#define vec vector<int>
#define vvec vector<vec>
#define pvec vector<vector<pint>>
#define tint tuple<int, int, int>
#define mt make_tuple

int n, m, s;
vvec to;
pvec cost;

const int inf = 1LL << 60;

int dp[60][3000];
// その状態までにかかる時間
int c[60], d[60];

bool chmin(int &a, int b) {
  if (a > b) {
    swap(a, b);
    return true;
  } else {
    return false;
  }
}

void Dijkstra(int a, int b) {

  b = min(b, 2999LL);

  dp[a][b] = 0;

  priority_queue<tint, vector<tint>, greater<tint>> Q;
  // {時間、位置、枚数}

  Q.push(mt(0, a, b));

  while (!Q.empty()) {

    auto p = Q.top();
    Q.pop();

    int time = get<0>(p);
    int pos = get<1>(p);
    int num = get<2>(p);

    if (time > dp[pos][num]) {
      continue;
    }

    for (int i = 0; i < (int)to[pos].size(); i++) {

      int length = cost[pos][i].second;
      int silver = cost[pos][i].first;

      int next = to[pos][i];

      int res = min(num + c[pos], 2999LL);

      int res2 = num - silver;

      if (chmin(dp[pos][res], dp[pos][num] + d[pos])) {
        Q.push(mt(dp[pos][res], pos, res));
      }

      if (res2 >= 0) {
        if (chmin(dp[next][res2], dp[pos][num] + length)) {
          Q.push(mt(dp[next][res2], next, res2));
        }
      }

    } // for-u
  }   // while-Q

  return;
}

signed main(void) {

  cin >> n >> m >> s;
  to.resize(n);
  cost.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    to[u].push_back(v);
    to[v].push_back(u);
    cost[u].push_back({a, b});
    cost[v].push_back({a, b});
  }

  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 3000; j++) {
      dp[i][j] = inf;
    }
  }

  Dijkstra(0, s);

  int ans = inf;

  for (int i = 1; i < n; i++) {
    int ans = inf;

    for (int j = 0; j < 3000; j++) {

      ans = min(ans, dp[i][j]);
    }

    cout << ans << endl;
  }

  return 0;
}