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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n, m, S;
vec U(100), V(100), A(100), B(100), C(50), D(50);
struct edge {
  ll to, cost, money;
};
vector<edge> G[200001];
ll d[51][2501], INF = 1e18;
int main() {
  cin >> n >> m >> S;
  rep(i, m) cin >> U[i] >> V[i] >> A[i] >> B[i],
      G[U[i]].push_back({V[i], B[i], A[i]}),
      G[V[i]].push_back({U[i], B[i], A[i]});
  rep(i, n) cin >> C[i + 1] >> D[i + 1];
  priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> que;
  rep(i, n) fill(d[i + 1], d[i + 1] + 2501, INF);
  if (S > 2500)
    S = 2500;
  d[1][S] = 0;
  que.push(make_pair(0, P(1, S)));
  while (!que.empty()) {
    pair<ll, P> p = que.top();
    que.pop();
    ll v = p.second.first, money = p.second.second;
    if (d[v][money] < p.first)
      continue;
    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (money >= e.money && d[e.to][money - e.money] > d[v][money] + e.cost) {
        d[e.to][money - e.money] = d[v][money] + e.cost,
                        que.push(make_pair(d[e.to][money - e.money],
                                           P(e.to, money - e.money)));
      }
    }
    for (ll i = 1; true; i++) {
      if (money + C[v] * i > 2500)
        break;
      if (d[v][money + C[v] * i] > d[v][money] + D[v] * i)
        d[v][money + C[v] * i] = d[v][money] + D[v] * i,
                            que.push(make_pair(d[v][money + C[v] * i],
                                               P(v, money + C[v] * i)));
    }
  }
  rep(i, n - 1) {
    ll x = INF;
    rep(j, 2501) x = min(x, d[i + 2][j]);
    cout << x << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n, m, S;
vector<int> U(100), V(100), A(100), B(100), C(50), D(50);
struct edge {
  int to, cost, money;
};
vector<edge> G[200001];
int d[51][2501], INF = 1e9;
int main() {
  cin >> n >> m >> S;
  rep(i, m) cin >> U[i] >> V[i] >> A[i] >> B[i],
      G[U[i]].push_back({V[i], B[i], A[i]}),
      G[V[i]].push_back({U[i], B[i], A[i]});
  rep(i, n) cin >> C[i + 1] >> D[i + 1];
  priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> que;
  rep(i, n) fill(d[i + 1], d[i + 1] + 2501, INF);
  if (S > 2500)
    S = 2500;
  d[1][S] = 0;
  que.push(make_pair(0, P(1, S)));
  while (!que.empty()) {
    pair<int, P> p = que.top();
    que.pop();
    int v = p.second.first, money = p.second.second;
    if (d[v][money] < p.first)
      continue;
    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (money >= e.money && d[e.to][money - e.money] > d[v][money] + e.cost) {
        d[e.to][money - e.money] = d[v][money] + e.cost,
                        que.push(make_pair(d[e.to][money - e.money],
                                           P(e.to, money - e.money)));
      }
    }
    for (int i = 1; true; i++) {
      if (money + C[v] * i > 2500)
        break;
      if (d[v][money + C[v] * i] > d[v][money] + D[v] * i)
        d[v][money + C[v] * i] = d[v][money] + D[v] * i,
                            que.push(make_pair(d[v][money + C[v] * i],
                                               P(v, money + C[v] * i)));
    }
  }
  rep(i, n - 1) {
    int x = INF;
    rep(j, 2501) x = min(x, d[i + 2][j]);
    cout << x << "\\n";
  }
}