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

#include <bits/stdc++.h>
#define ll long long
#define inf 0x7fffffff
#define infll 0x7fffffffffffffff
#define clr(c) memset(c, 0, sizeof(c))
using namespace std;
int mod = 998244353;
const int M = 1e6 + 10;
const int N = 2e5 + 10;
inline ll read() {
  ll b = 1, sum = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      b = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return b * sum;
}
struct node {
  int x, y;
  int nx;
  ll a, b;
} e[300];
struct city {
  ll c, d;
} c[300];
int head[300], ecnt;
int T, n, m, k, s;
ll dis[100][2600];
void add(int x, int y, int a, int b) {
  ecnt++;
  e[ecnt].x = x;
  e[ecnt].y = y;
  e[ecnt].a = a;
  e[ecnt].b = b;
  e[ecnt].nx = head[x];
  head[x] = ecnt;
}
void input() {
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    int a = read(), b = read();
    add(x, y, a, b);
    add(y, x, a, b);
  }
  for (int i = 1; i <= n; i++) {
    int cc = read(), d = read();
    c[i].c = cc;
    c[i].d = d;
  }
}
void solve() {
  int i, j;
  queue<pair<ll, ll>> q;

  dis[1][s] = 0;
  q.push({1, s});
  while (q.size()) {
    ll x = q.front().first, w = q.front().second;
    q.pop();
    for (i = head[x]; i; i = e[i].nx) {
      ll y = e[i].y;
      ll a = e[i].a, b = e[i].b;
      ll wei = w - a;
      if (wei >= 0 && dis[y][wei] > dis[x][w] + b) {
        dis[y][wei] = dis[x][w] + b;
        q.push({y, wei});
      }
    }
    ll cc = c[x].c, d = c[x].d;
    ll wei = min(2500ll, cc + w);
    if (dis[x][wei] > dis[x][w] + d) {
      dis[x][wei] = dis[x][w] + d;
      q.push({x, wei});
    }
  }
}
int main() {
  int i, j;
  input();
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 2500; j++)
      dis[i][j] = infll / 100ll;
  }
  s = min(s, 2500);
  solve();
  for (i = 2; i <= n; i++) {
    ll ans = infll;
    for (j = 0; j <= 2500; j++)
      ans = min(ans, dis[i][j]);
    printf("%lld\\n", ans);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define inf 0x7fffffff
#define infll 0x7fffffffffffffff
#define clr(c) memset(c, 0, sizeof(c))
using namespace std;
int mod = 998244353;
const int M = 1e6 + 10;
const int N = 2e5 + 10;
inline ll read() {
  ll b = 1, sum = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      b = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return b * sum;
}
struct node {
  int x, y;
  int nx;
  ll a, b;
} e[300];
struct city {
  ll c, d;
} c[300];
int head[300], ecnt;
int T, n, m, k, s;
ll dis[100][2600];
void add(int x, int y, int a, int b) {
  ecnt++;
  e[ecnt].x = x;
  e[ecnt].y = y;
  e[ecnt].a = a;
  e[ecnt].b = b;
  e[ecnt].nx = head[x];
  head[x] = ecnt;
}
void input() {
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    int a = read(), b = read();
    add(x, y, a, b);
    add(y, x, a, b);
  }
  for (int i = 1; i <= n; i++) {
    int cc = read(), d = read();
    c[i].c = cc;
    c[i].d = d;
  }
}
void solve() {
  int i, j;
  queue<pair<ll, ll>> q;

  dis[1][s] = 0;
  q.push({1, s});
  while (q.size()) {
    ll x = q.front().first, w = q.front().second;
    q.pop();
    for (i = head[x]; i; i = e[i].nx) {
      ll y = e[i].y;
      ll a = e[i].a, b = e[i].b;
      ll wei = w - a;
      if (wei >= 0 && dis[y][wei] > dis[x][w] + b) {
        dis[y][wei] = dis[x][w] + b;
        q.push({y, wei});
      }
    }
    ll cc = c[x].c, d = c[x].d;
    ll wei = min(2500ll, cc + w);
    if (dis[x][wei] > dis[x][w] + d) {
      dis[x][wei] = dis[x][w] + d;
      q.push({x, wei});
    }
  }
}
int main() {
  int i, j;
  input();
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 2500; j++)
      dis[i][j] = inf;
  }
  solve();
  for (i = 2; i <= n; i++) {
    ll ans = inf;
    for (j = 0; j <= 2500; j++)
      ans = min(ans, dis[i][j]);
    printf("%lld\\n", ans);
  }
  return 0;
}