Problem p02703 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\\n" : "No\\n"); }

struct Edge {
  int to;
  ll time;
  ll cost;
};

int main() {
  int n, m;
  ll s;
  cin >> n >> m >> s;
  vector<Edge> Graph[n];
  for (int i = 0; i < m; i++) {
    int u, v, a;
    ll b;
    cin >> u >> v >> a >> b;
    u--, v--;
    Graph[u].push_back(Edge{v, b, -a});
    Graph[v].push_back(Edge{u, b, -a});
  }
  for (int i = 0; i < n; i++) {
    ll c, d;
    cin >> c >> d;
    Graph[i].push_back(Edge{i, d, c});
  }
  // cerr << "Input OK\\n";
  vector<vector<ll>> dp(n, vector<ll>(2600, INF));
  priority_queue<tuple<ll, ll, int>, vector<tuple<ll, ll, int>>,
                 greater<tuple<ll, ll, int>>>
      pq;
  pq.push(make_tuple(0, min(s, 2510ll), 0));
  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    ll time = get<0>(t);
    ll coin = get<1>(t);
    int idx = get<2>(t);
    // cerr << time << ' ' << coin << ' ' << idx << '\\n';
    if (coin > 2510) {
      pq.push(make_tuple(time, 2510, idx));
      continue;
    }
    if (dp[idx][coin] <= time) {
      continue;
    }
    dp[idx][coin] = time;
    for (auto e : Graph[idx]) {
      if (coin + e.cost >= 0) {
        pq.push(make_tuple(time + e.time, coin + e.cost, e.to));
      }
    }
  }
  for (int i = 1; i < n; i++) {
    ll ans = INF;
    for (auto j : dp[i])
      chmin(ans, j);
    cout << ans << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\\n" : "No\\n"); }

struct Edge {
  int to;
  ll time;
  ll cost;
};

int main() {
  int n, m;
  ll s;
  cin >> n >> m >> s;
  vector<Edge> Graph[n];
  for (int i = 0; i < m; i++) {
    int u, v, a;
    ll b;
    cin >> u >> v >> a >> b;
    u--, v--;
    Graph[u].push_back(Edge{v, b, -a});
    Graph[v].push_back(Edge{u, b, -a});
  }
  for (int i = 0; i < n; i++) {
    ll c, d;
    cin >> c >> d;
    Graph[i].push_back(Edge{i, d, c});
  }
  // cerr << "Input OK\\n";
  vector<vector<ll>> dp(n, vector<ll>(2510, INF));
  priority_queue<tuple<ll, ll, int>, vector<tuple<ll, ll, int>>,
                 greater<tuple<ll, ll, int>>>
      pq;
  pq.push(make_tuple(0, s, 0));
  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    ll time = get<0>(t);
    ll coin = get<1>(t);
    int idx = get<2>(t);
    // cerr << time << ' ' << coin << ' ' << idx << '\\n';
    if (coin > 2500) {
      pq.push(make_tuple(time, 2505, idx));
      continue;
    }
    if (dp[idx][coin] <= time) {
      continue;
    }
    dp[idx][coin] = time;
    for (auto e : Graph[idx]) {
      if (coin + e.cost >= 0) {
        pq.push(make_tuple(time + e.time, coin + e.cost, e.to));
      }
    }
  }
  for (int i = 1; i < n; i++) {
    ll ans = INF;
    for (auto j : dp[i])
      chmin(ans, j);
    cout << ans << '\\n';
  }
}