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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  using T = pair<ll, pair<ll, ll>>;
  vector<vector<T>> g(n);
  s = min(s, 2600LL);
  REP(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }
  vector<ll> c(n), d(n);
  REP(i, n) {
    cin >> c[i] >> d[i];
    g[i].push_back({i, {-c[i], d[i]}});
  }
  vector<vector<ll>> dists(n, vector<ll>(2700, INF));
  priority_queue<T, vector<T>, greater<T>> que;
  que.push({0, {0, s}});
  while (!que.empty()) {
    auto [dist, tmp] = que.top();
    que.pop();
    auto [now, tip] = tmp;
    tip = min(tip, 2600LL);
    if (dists[now][tip] <= dist)
      continue;
    dists[now][tip] = dist;
    for (auto [next, ab] : g[now]) {
      auto [a, b] = ab;
      if (tip < a)
        continue;
      que.push({dist + b, {next, tip - a}});
    }
  }
  for (ll t = 1; t < n; t++) {
    cout << *min_element(dists[t].begin(), dists[t].end()) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  using T = pair<ll, pair<ll, ll>>;
  vector<vector<T>> g(n);
  s = min(s, 3000LL);
  REP(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }
  vector<ll> c(n), d(n);
  REP(i, n) {
    cin >> c[i] >> d[i];
    g[i].push_back({i, {-c[i], d[i]}});
  }
  for (ll t = 1; t < n; t++) {
    vector<vector<ll>> dists(n, vector<ll>(3000, INF));
    priority_queue<T, vector<T>, greater<T>> que;
    que.push({0, {0, s}});
    while (!que.empty()) {
      auto [dist, tmp] = que.top();
      que.pop();
      auto [now, tip] = tmp;
      tip = min(tip, 2600LL);
      if (dists[now][tip] <= dist)
        continue;
      dists[now][tip] = dist;
      for (auto [next, ab] : g[now]) {
        auto [a, b] = ab;
        if (tip < a)
          continue;
        que.push({dist + b, {next, tip - a}});
      }
    }
    cout << *min_element(dists[t].begin(), dists[t].end()) << endl;
  }
}