Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - 48, ch = getchar();
}
const int N = 55, M = 210;
int n, m, s, c[N], d[N], f[N][N * N];
int cnt, h[N], to[M], nxt[M], a[N], b[N];
inline void add(int u, int v, int x, int y) {
  to[++cnt] = v, a[cnt] = x, b[cnt] = y, nxt[cnt] = h[u], h[u] = cnt;
}
struct node {
  int res, u, s;
  inline bool operator<(const node &x) const { return res > x.res; }
};
priority_queue<node> q;
inline void Dij() {
  q.push(node{0, 1, s});
  while (!q.empty()) {
    node t = q.top();
    q.pop();
    if (f[t.u][t.s] < t.res)
      continue;
    for (int i = h[t.u]; i; i = nxt[i])
      if (t.s >= a[i] && f[to[i]][t.s - a[i]] > t.res + b[i])
        f[to[i]][t.s - a[i]] = t.res + b[i],
                       q.push(node{t.res + b[i], to[i], t.s - a[i]});
    int qwq = min(2500ll, t.s + c[t.u]);
    if (f[t.u][qwq] > t.res + d[t.u])
      f[t.u][qwq] = t.res + d[t.u], q.push(node{t.res + d[t.u], t.u, qwq});
  }
}
signed main() {
  read(n), read(m), read(s);
  s = min(s, 2500ll);
  memset(f, 0x3f, sizeof(f));
  f[1][s] = 0;
  for (int i = 1, u, v, x, y; i <= m; ++i) {
    read(u), read(v), read(x), read(y);
    add(u, v, x, y), add(v, u, x, y);
  }
  for (int i = 1; i <= n; ++i)
    read(c[i]), read(d[i]);
  Dij();
  for (int i = 2; i <= n; ++i) {
    int res = f[0][0];
    for (int j = 0; j <= 2500; ++j)
      res = min(res, f[i][j]);
    printf("%lld\n", res);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - 48, ch = getchar();
}
const int N = 55, M = 210;
int n, m, s, c[N], d[N], f[N][N * N];
int cnt, h[N], to[M], nxt[M], a[M], b[M];
inline void add(int u, int v, int x, int y) {
  to[++cnt] = v, a[cnt] = x, b[cnt] = y, nxt[cnt] = h[u], h[u] = cnt;
}
struct node {
  int res, u, s;
  inline bool operator<(const node &x) const { return res > x.res; }
};
priority_queue<node> q;
inline void Dij() {
  q.push(node{0, 1, s});
  while (!q.empty()) {
    node t = q.top();
    q.pop();
    if (f[t.u][t.s] < t.res)
      continue;
    for (int i = h[t.u]; i; i = nxt[i])
      if (t.s >= a[i] && f[to[i]][t.s - a[i]] > t.res + b[i])
        f[to[i]][t.s - a[i]] = t.res + b[i],
                       q.push(node{t.res + b[i], to[i], t.s - a[i]});
    int qwq = min(2500ll, t.s + c[t.u]);
    if (f[t.u][qwq] > t.res + d[t.u])
      f[t.u][qwq] = t.res + d[t.u], q.push(node{t.res + d[t.u], t.u, qwq});
  }
}
signed main() {
  read(n), read(m), read(s);
  s = min(s, 2500ll);
  memset(f, 0x3f, sizeof(f));
  f[1][s] = 0;
  for (int i = 1, u, v, x, y; i <= m; ++i) {
    read(u), read(v), read(x), read(y);
    add(u, v, x, y), add(v, u, x, y);
  }
  for (int i = 1; i <= n; ++i)
    read(c[i]), read(d[i]);
  Dij();
  for (int i = 2; i <= n; ++i) {
    int res = f[0][0];
    for (int j = 0; j <= 2500; ++j)
      res = min(res, f[i][j]);
    printf("%lld\n", res);
  }
  return 0;
}