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

/* This code is written by Nemlit */
#include <bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\\n", __LINE__)
#define file(a)                                                                \\
  freopen(#a ".in", "r", stdin);                                               \\
  freopen(#a ".out", "w", stdout)
#define rep(i, a, b) for (re int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (re int i = (b); i >= (a); --i)
#define Next(i, u) for (re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 10234567890000000
#define mod 1000000007
#define lb(x) (x) & (-(x))
il int read() {
  re int x = 0, f = 1;
  re char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - 48, c = getchar();
  return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1)
      r = Mul(r, a);
    a = Mul(a, a), b >>= 1;
  }
  return r;
}
#define ls k * 2
#define rs k * 2 + 1
#define maxn 55
namespace Graph {
int head[maxn], cnt;
struct edge {
  int v, next, a, b;
} e[maxn << 2];
il void add(int u, int v, int a, int b) {
  e[++cnt] = (edge){v, head[u], a, b}, head[u] = cnt;
}
} // namespace Graph
using namespace Graph;
int n, m, dp[maxn][5005], s, c[maxn], d[maxn], vis[maxn][5005];
struct node {
  int u, v;
};
queue<node> q;
signed main() {
  n = read(), m = read(), s = min(read(), 5000ll);
  rep(i, 1, m) {
    int u = read(), v = read(), a = read(), b = read();
    add(u, v, a, b), add(v, u, a, b);
  }
  mem(dp, 63), dp[1][s] = 0;
  rep(i, 1, n) c[i] = min(2500ll, read()), d[i] = read();
  q.push((node){1, s});
  while (!q.empty()) {
    int u = q.front().u, l = q.front().v;
    q.pop(), vis[u][l] = 0;
    Next(i, u) {
      int v = e[i].v;
      if (l >= e[i].a && dp[u][l] + e[i].b < dp[v][l - e[i].a]) {
        dp[v][l - e[i].a] = dp[u][l] + e[i].b;
        if (vis[v][l - e[i].a] == 0)
          q.push((node){v, l - e[i].a}), vis[v][l - e[i].a] = 1;
      }
    }
    int tim = dp[u][l];
    l += c[u], tim += d[u];
    while (l <= 5000) {
      if (tim < dp[u][l]) {
        dp[u][l] = tim;
        if (vis[u][l] == 0)
          q.push((node){u, l}), vis[u][l] = 1;
      }
      l += c[u], tim += d[u];
    }
  }
  rep(i, 2, n) {
    int ans = inf;
    rep(j, 0, 5000) ans = min(ans, dp[i][j]);
    printf("%lld\\n", ans);
  }
  return 0;
}


Error: 0

Fixed submission:

/* This code is written by Nemlit */
#include <bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\\n", __LINE__)
#define file(a)                                                                \\
  freopen(#a ".in", "r", stdin);                                               \\
  freopen(#a ".out", "w", stdout)
#define rep(i, a, b) for (re int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (re int i = (b); i >= (a); --i)
#define Next(i, u) for (re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 10234567890000
#define mod 1000000007
#define lb(x) (x) & (-(x))
il int read() {
  re int x = 0, f = 1;
  re char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - 48, c = getchar();
  return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1)
      r = Mul(r, a);
    a = Mul(a, a), b >>= 1;
  }
  return r;
}
#define ls k * 2
#define rs k * 2 + 1
#define maxn 55
namespace Graph {
int head[maxn], cnt;
struct edge {
  int v, next, a, b;
} e[maxn << 1];
il void add(int u, int v, int a, int b) {
  e[++cnt] = (edge){v, head[u], a, b}, head[u] = cnt;
}
} // namespace Graph
using namespace Graph;
int n, m, dp[maxn][255], s, c[maxn], d[maxn], vis[maxn][255];
struct node {
  int u, v;
};
queue<node> q;
signed main() {
  n = read(), m = read(), s = min(read(), 250ll);
  rep(i, 1, m) {
    int u = read(), v = read(), a = read(), b = read();
    add(u, v, a, b), add(v, u, a, b);
  }
  mem(dp, 63), dp[1][s] = 0;
  rep(i, 1, n) c[i] = read(), d[i] = read();
  q.push((node){1, s});
  while (!q.empty()) {
    int u = q.front().u, l = q.front().v;
    q.pop(), vis[u][l] = 0;
    Next(i, u) {
      int v = e[i].v;
      if (l >= e[i].a && dp[u][l] + e[i].b < dp[v][l - e[i].a]) {
        dp[v][l - e[i].a] = dp[u][l] + e[i].b;
        if (vis[v][l - e[i].a] == 0)
          q.push((node){v, l - e[i].a}), vis[v][l - e[i].a] = 1;
      }
    }
    int tim = dp[u][l];
    l += c[u], tim += d[u];
    while (l <= 250) {
      if (tim < dp[u][l]) {
        dp[u][l] = tim;
        if (vis[u][l] == 0)
          q.push((node){u, l}), vis[u][l] = 1;
      }
      l += c[u], tim += d[u];
    }
  }
  rep(i, 2, n) {
    int ans = inf;
    rep(j, 0, 250) ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
  return 0;
}