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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll inf = 0x3f3f3f3f;
const int N = 100;
struct edge {
  int v;
  ll s, t;
  int ne;
} e[N << 1];
int n, m, cnt, head[N];
ll s, dis[N], c[N], d[N], dp[N][3000];

void add(int u, int v, ll w, ll t) {
  e[++cnt] = {v, w, t, head[u]};
  head[u] = cnt;
  e[++cnt] = {u, w, t, head[v]};
  head[v] = cnt;
}

void bfs() {
  if (s >= 2500)
    s = 2500;
  dp[1][s] = 0;
  for (int up = 1; up <= n + 2; ++up) {
    for (int i = 1; i <= n; ++i) {
      for (int j = head[i]; j; j = e[j].ne) {
        for (int now = 0; now <= 2500; ++now) {
          if (now - e[j].s >= 0) {
            dp[i][now - e[j].s] =
                min(dp[i][now - e[j].s], dp[e[j].v][now] + e[j].t);
            // dp[e[j].v][now-e[j].s]=min(dp[e[j].v][now-e[j].s],dp[i][now]+e[j].t);
            // dp[e[j].v][now]=min(dp[e[j].v][now],dp[i][now-e[j].s]+e[j].t);
          }
        }
      }

      for (int now = 0; now <= 2500; now++) {
        if (now - c[i] >= 0) {
          dp[i][now] = min(dp[i][now - c[i]] + d[i], dp[i][now]);
        }
      }
    }
  }
}
void solve() {
  cin >> n >> m >> s;
  // scanf("%d%d%lld",&n,&m,&s);
  mem(dp, inf);
  rep(i, 1, m) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    // scanf("%d %d %lld %lld",&u,&v,&a,&b);
    add(u, v, a, b);
  }
  rep(i, 1, n) cin >> c[i] >> d[i];
  bfs();
  for (int i = 2; i <= n; ++i) {
    ll ans = 1e18;
    for (int now = 0; now <= 2500; ++now)
      ans = min(ans, dp[i][now]);
    printf("%lld\\n", ans);
  }
}
int main() { solve(); }


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
#define mem(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll inf = 0x3f3f3f3f;
const int N = 100;
struct edge {
  int v;
  ll s, t;
  int ne;
} e[N << 1];
int n, m, cnt, head[N];
ll s, dis[N], c[N], d[N], dp[N][3000];

void add(int u, int v, ll w, ll t) {
  e[++cnt] = {v, w, t, head[u]};
  head[u] = cnt;
  e[++cnt] = {u, w, t, head[v]};
  head[v] = cnt;
}

void bfs() {
  if (s >= 2500)
    s = 2500;
  dp[1][s] = 0;
  for (int up = 1; up <= n + 2; ++up) {
    for (int i = 1; i <= n; ++i) {
      for (int j = head[i]; j; j = e[j].ne) {
        for (int now = 0; now <= 2500; ++now) {
          if (now - e[j].s >= 0) {
            dp[e[j].v][now - e[j].s] =
                min(dp[e[j].v][now - e[j].s], dp[i][now] + e[j].t);
            // dp[e[j].v][now]=min(dp[e[j].v][now],dp[i][now-e[j].s]+e[j].t);
          }
        }
      }

      for (int now = 0; now <= 2500; now++) {
        if (now - c[i] >= 0) {
          dp[i][now] = min(dp[i][now - c[i]] + d[i], dp[i][now]);
        }
      }
    }
  }
}
void solve() {
  cin >> n >> m >> s;
  scanf("%d%d%lld", &n, &m, &s);
  mem(dp, inf);
  rep(i, 1, m) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    // scanf("%d %d %lld %lld",&u,&v,&a,&b);
    add(u, v, a, b);
  }
  rep(i, 1, n) cin >> c[i] >> d[i];
  bfs();
  for (int i = 2; i <= n; ++i) {
    ll ans = 1e18;
    for (int now = 0; now <= 2500; ++now)
      ans = min(ans, dp[i][now]);
    printf("%lld\\n", ans);
  }
}
int main() { solve(); }