Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS const ll LINF = 1LL << 60;
  const ll SMAX = 2500;
  using plpll = pair<ll, pll>;
  auto makep = [](const ll time, const int to, const int sil) {
    return make_pair(time, make_pair(to, sil));
  };

  ll N, M;
  cin >> N >> M;
  ll S;
  cin >> S;
  vector<vector<plpll>> g(N);
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    ll toll, t;
    cin >> toll >> t;
    g[u].push_back(makep(t, v, toll));
    g[v].push_back(makep(t, u, toll));
  }
  vector<ll> C(N), D(N);
  REP(i, N) cin >> C[i] >> D[i];

  S = min(S, SMAX);
  vector<vector<ll>> dp(N, vector<ll>(SMAX + 5, LINF));
  dp[0][0] = 0;

  priority_queue<plpll, vector<plpll>, greater<plpll>> dj;

  dj.push(makep(0, 0, S));

  while (!dj.empty()) {
    plpll p = dj.top();
    dj.pop();
    ll time = p.first;
    ll cnt = p.second.first;
    ll sil = p.second.second;
    if (dp[cnt][sil] < time)
      continue;

    // 1回分交換を追加
    if (sil + C[cnt] <= SMAX) {
      ll sc = sil + C[cnt];
      ll tc = time + D[cnt];
      if (dp[cnt][sc] > tc) {
        dp[cnt][sc] = tc;
        dj.push(makep(tc, cnt, sc));
      }
    }

    // 辺を通る
    for (auto p2 : g[cnt]) {
      ll time2 = time + p2.first;
      ll to = p2.second.first;
      ll sil2 = sil - p2.second.second;
      if (sil2 < 0)
        continue;
      if (dp[to][sil2] < time2)
        continue;
      dp[to][sil2] = time2;
      dj.push(makep(time2, to, sil2));
    }
  }

  FOR(i, 1, N) {
    ll ans = LINF;
    REP(j, SMAX) ans = min(ans, dp[i][j]);
    OUT(ans)
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS const ll LINF = 1LL << 60;
  const ll SMAX = 2500;
  using plpll = pair<ll, pll>;
  auto makep = [](const ll time, const int to, const int sil) {
    return make_pair(time, make_pair(to, sil));
  };

  ll N, M;
  cin >> N >> M;
  ll S;
  cin >> S;
  vector<vector<plpll>> g(N);
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    ll toll, t;
    cin >> toll >> t;
    g[u].push_back(makep(t, v, toll));
    g[v].push_back(makep(t, u, toll));
  }
  vector<ll> C(N), D(N);
  REP(i, N) cin >> C[i] >> D[i];

  S = min(S, SMAX);
  vector<vector<ll>> dp(N, vector<ll>(SMAX + 5, LINF));
  dp[0][0] = 0;

  priority_queue<plpll, vector<plpll>, greater<plpll>> dj;

  dj.push(makep(0, 0, S));

  while (!dj.empty()) {
    plpll p = dj.top();
    dj.pop();
    ll time = p.first;
    ll cnt = p.second.first;
    ll sil = p.second.second;
    if (dp[cnt][sil] < time)
      continue;

    // 1回分交換を追加
    if (sil + C[cnt] <= SMAX) {
      ll sc = sil + C[cnt];
      ll tc = time + D[cnt];
      if (dp[cnt][sc] > tc) {
        dp[cnt][sc] = tc;
        dj.push(makep(tc, cnt, sc));
      }
    }

    // 辺を通る
    for (auto p2 : g[cnt]) {
      ll time2 = time + p2.first;
      ll to = p2.second.first;
      ll sil2 = sil - p2.second.second;
      if (sil2 < 0)
        continue;
      if (dp[to][sil2] > time2) {
        dp[to][sil2] = time2;
        dj.push(makep(time2, to, sil2));
      }
    }
  }

  FOR(i, 1, N) {
    ll ans = LINF;
    REP(j, SMAX) ans = min(ans, dp[i][j]);
    OUT(ans)
  }

  return 0;
}