Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 60;
const int tot = 2600;
const ll inf = 1e18;
int n, m;
ll s;
vector<pair<int, pair<int, int>>> G[maxn];
ll dp[maxn][tot];
ll c[120], d[120];
void dijk() {
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < tot; j++)
      dp[i][j] = inf;
  priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>,
                 greater<pair<ll, pair<int, int>>>>
      pq;
  pq.push({0, {1, s}});
  pair<ll, pair<int, int>> tp;
  while (!pq.empty()) {
    tp = pq.top(), pq.pop();
    int nowpos = tp.second.first;
    ll nowcost = tp.first;
    ll nows = (ll)tp.second.second;
    for (auto &to : G[nowpos]) {
      ll newcost = nowcost + to.second.second;
      ll nwe = nows - to.second.first;
      if (nwe >= 0) {
        if (dp[to.first][nwe] > newcost) {
          dp[to.first][nwe] = newcost;
          pq.push({newcost, {to.first, nwe}});
        }
      }
    }
    ll nwecost = nowcost + d[nowpos];
    ll nwe = min(nows + c[nowpos], (ll)tot - 1);
    if (dp[nowpos][nwe] > nwecost) {
      dp[nowpos][nwe] = nwecost;
      pq.push({nwecost, {nowpos, nwe}});
    }
  }
}

void solve() {
  cin >> n >> m >> s;
  int u, v, a, b;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> a >> b;
    G[u].push_back({v, {a, b}});
    G[v].push_back({u, {a, b}});
  }
  for (int i = 1; i <= n; i++)
    cin >> c[i] >> d[i];
  dijk();
  ll ans;
  for (int i = 2; i <= n; i++) {
    ans = inf;
    for (int j = 0; j < tot; j++)
      ans = min(dp[i][j], ans);
    cout << ans << "\n";
  }
}

int main() {
  // freopen("in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T-- > 0)
    solve();
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 60;
const int tot = 2600;
const ll inf = 1e18;
int n, m;
ll s;
vector<pair<int, pair<int, int>>> G[maxn];
ll dp[maxn][tot];
ll c[120], d[120];
void dijk() {
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < tot; j++)
      dp[i][j] = inf;
  priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>,
                 greater<pair<ll, pair<int, int>>>>
      pq;
  pq.push({0, {1, s}});
  pair<ll, pair<int, int>> tp;
  while (!pq.empty()) {
    tp = pq.top(), pq.pop();
    int nowpos = tp.second.first;
    ll nowcost = tp.first;
    ll nows = (ll)tp.second.second;
    for (auto &to : G[nowpos]) {
      ll newcost = nowcost + to.second.second;
      ll nwe = min(nows - to.second.first, (ll)tot - 1);
      if (nwe >= 0) {
        if (dp[to.first][nwe] > newcost) {
          dp[to.first][nwe] = newcost;
          pq.push({newcost, {to.first, nwe}});
        }
      }
    }
    ll nwecost = nowcost + d[nowpos];
    ll nwe = min(nows + c[nowpos], (ll)tot - 1);
    if (dp[nowpos][nwe] > nwecost) {
      dp[nowpos][nwe] = nwecost;
      pq.push({nwecost, {nowpos, nwe}});
    }
  }
}

void solve() {
  cin >> n >> m >> s;
  int u, v, a, b;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> a >> b;
    G[u].push_back({v, {a, b}});
    G[v].push_back({u, {a, b}});
  }
  for (int i = 1; i <= n; i++)
    cin >> c[i] >> d[i];
  dijk();
  ll ans;
  for (int i = 2; i <= n; i++) {
    ans = inf;
    for (int j = 0; j < tot; j++)
      ans = min(dp[i][j], ans);
    cout << ans << "\n";
  }
}

int main() {
  // freopen("in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T-- > 0)
    solve();
}