Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < ((ll)(n)); i++)
#define reg(i, a, b) for (ll i = ((ll)(a)); i <= ((ll)(b)); i++)
#define irep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (ll i = ((ll)(b)); i >= ((ll)(a)); i--)
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
template <class T = int> void print(vector<T> v) {
  for (auto a : v)
    cout << a << " ";
  cout << endl;
}

/*
銀貨の数だけ新たなグラフを作る
*/

ll n, m, s, d[51][2501], gc[51], gt[51];
vector<ll> v[51], c[51], t[51];

int main(void) {
  cin >> n >> m >> s;
  rep(i, m) {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    v[x].push_back(y);
    v[y].push_back(x);
    c[x].push_back(a); // 消費コイン
    c[y].push_back(a); //
    t[x].push_back(b); // 消費時間
    t[y].push_back(b); //
  }
  reg(i, 1, n) cin >> gc[i] >> gt[i];
  rep(i, 51) rep(j, 2501) d[i][j] = 1e15;
  s = min(s, 2500LL);
  d[1][s] = 0;
  priority_queue<pair<ll, pair<ll, ll>>> q;
  q.push({0, {1, s}});
  while (!q.empty()) {
    auto x = q.top();
    q.pop();
    auto y = x.second;
    ll cur_t = x.first, p = y.first, cur_c = y.second;
    if (d[p][min(2500LL, cur_c + gc[p])] > d[p][cur_c] + gt[p]) { // コイン補充
      d[p][min(2500LL, cur_c + gc[p])] = d[p][cur_c] + gt[p];
      q.push(
          {d[p][min(2500LL, cur_c + gc[p])], {p, min(2500LL, cur_c + gc[p])}});
    }
    rep(i, v[p].size()) { // 移動
      ll r = v[p][i], dt = t[p][i], dc = c[p][i];
      if (cur_c - dc >= 0 && d[r][cur_c - dc] > d[p][cur_c] + dt) {
        d[r][cur_c - dc] = d[p][cur_c] + dt;
        q.push({d[r][cur_c - dc], {r, cur_c - dc}});
      }
    }
  }
  reg(i, 2, n) {
    ll ans = 1e18;
    rep(j, 2501) { ans = min(ans, d[i][j]); }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < ((ll)(n)); i++)
#define reg(i, a, b) for (ll i = ((ll)(a)); i <= ((ll)(b)); i++)
#define irep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (ll i = ((ll)(b)); i >= ((ll)(a)); i--)
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
template <class T = int> void print(vector<T> v) {
  for (auto a : v)
    cout << a << " ";
  cout << endl;
}

/*
銀貨の数だけ新たなグラフを作る
*/

ll n, m, s, d[51][2501], gc[51], gt[51];
vector<ll> v[51], c[51], t[51];

int main(void) {
  cin >> n >> m >> s;
  rep(i, m) {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    v[x].push_back(y);
    v[y].push_back(x);
    c[x].push_back(a); // 消費コイン
    c[y].push_back(a); //
    t[x].push_back(b); // 消費時間
    t[y].push_back(b); //
  }
  reg(i, 1, n) cin >> gc[i] >> gt[i];
  rep(i, 51) rep(j, 2501) d[i][j] = 1e15;
  s = min(s, 2500LL);
  d[1][s] = 0;
  priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>,
                 greater<pair<ll, pair<ll, ll>>>>
      q;
  q.push({0, {1, s}});
  while (!q.empty()) {
    auto x = q.top();
    q.pop();
    auto y = x.second;
    ll cur_t = x.first, p = y.first, cur_c = y.second;
    if (d[p][min(2500LL, cur_c + gc[p])] > d[p][cur_c] + gt[p]) { // コイン補充
      d[p][min(2500LL, cur_c + gc[p])] = d[p][cur_c] + gt[p];
      q.push(
          {d[p][min(2500LL, cur_c + gc[p])], {p, min(2500LL, cur_c + gc[p])}});
    }
    rep(i, v[p].size()) { // 移動
      ll r = v[p][i], dt = t[p][i], dc = c[p][i];
      if (cur_c - dc >= 0 && d[r][cur_c - dc] > d[p][cur_c] + dt) {
        d[r][cur_c - dc] = d[p][cur_c] + dt;
        q.push({d[r][cur_c - dc], {r, cur_c - dc}});
      }
    }
  }
  reg(i, 2, n) {
    ll ans = 1e18;
    rep(j, 2501) { ans = min(ans, d[i][j]); }
    cout << ans << endl;
  }
  return 0;
}