Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>

#define ll long long
#define int long long
#define FOR(i, x, y) for (int i = x; i <= y; ++i)
#define pb push_back
#define eb emplace_back
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int INF = 1e16;

struct Obj {
  int v, a, b;

  Obj(int x, int y, int z) { v = x, a = y, b = z; }

  Obj() { v = 0, a = 0, b = 0; }
};

int n, m, s, c[55], d[55];
vector<Obj> adj[55];
int dist[56 * 2600];
vector<pair<int, int>> graph[56 * 2600];

int encode(int i, int j) { return (i * 2501 + j); }

bool visited[56 * 2600];

void build(int i, int j) {
  int yeet = encode(i, j);

  if (j < 2500) {
    graph[yeet].eb(encode(i, min(2500LL, j + c[i])), d[i]);
  }

  for (auto &p : adj[i]) {
    int c = p.v, cost = p.a, w = p.b;
    if (j >= cost) {
      graph[yeet].eb(encode(c, j - cost), w);
    }
  }
}

void dijkstra(int v) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;

  pq.push({0, v});
  dist[v] = 0;

  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();

    if (visited[u])
      continue;

    visited[u] = true;

    for (auto &p : graph[u]) {
      int c = p.first, w = p.second;
      if (dist[c] > dist[u] + w) {
        dist[c] = dist[u] + w;
        pq.push({dist[c], c});
      }
    }
  }
}

void solve() {
  cin >> n >> m >> s;

  FOR(i, 1, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;

    adj[u].eb(v, a, b);
    adj[v].eb(u, a, b);
  }

  FOR(i, 1, n) cin >> c[i] >> d[i];

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 2500; ++j) {
      build(i, j);
    }
  }

  // cerr << "here\n";

  fill(dist, dist + 56 * 2600, INF);

  dijkstra(encode(1, s));

  for (int i = 2; i <= n; ++i) {
    int ans = 1e15;
    for (int j = 0; j <= 2500; ++j) {
      ans = min(ans, dist[encode(i, j)]);
    }
    cout << ans << '\n';
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t = 1;
  while (t--)
    solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>

#define ll long long
#define int long long
#define FOR(i, x, y) for (int i = x; i <= y; ++i)
#define pb push_back
#define eb emplace_back
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int INF = 1e16;

struct Obj {
  int v, a, b;

  Obj(int x, int y, int z) { v = x, a = y, b = z; }

  Obj() { v = 0, a = 0, b = 0; }
};

int n, m, s, c[55], d[55];
vector<Obj> adj[55];
int dist[56 * 2600];
vector<pair<int, int>> graph[56 * 2600];

int encode(int i, int j) { return (i * 2501 + j); }

bool visited[56 * 2600];

void build(int i, int j) {
  int yeet = encode(i, j);

  if (j < 2500) {
    graph[yeet].eb(encode(i, min(2500LL, j + c[i])), d[i]);
  }

  for (auto &p : adj[i]) {
    int c = p.v, cost = p.a, w = p.b;
    if (j >= cost) {
      graph[yeet].eb(encode(c, j - cost), w);
    }
  }
}

void dijkstra(int v) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;

  pq.push({0, v});
  dist[v] = 0;

  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();

    if (visited[u])
      continue;

    visited[u] = true;

    for (auto &p : graph[u]) {
      int c = p.first, w = p.second;
      if (dist[c] > dist[u] + w) {
        dist[c] = dist[u] + w;
        pq.push({dist[c], c});
      }
    }
  }
}

void solve() {
  cin >> n >> m >> s;

  FOR(i, 1, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;

    adj[u].eb(v, a, b);
    adj[v].eb(u, a, b);
  }

  FOR(i, 1, n) cin >> c[i] >> d[i];

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 2500; ++j) {
      build(i, j);
    }
  }

  // cerr << "here\n";

  fill(dist, dist + 56 * 2600, INF);

  dijkstra(encode(1, min(2500LL, s)));

  for (int i = 2; i <= n; ++i) {
    int ans = 1e15;
    for (int j = 0; j <= 2500; ++j) {
      ans = min(ans, dist[encode(i, j)]);
    }
    cout << ans << '\n';
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t = 1;
  while (t--)
    solve();
  return 0;
}