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

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
// const int mod=998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

struct edge {
  int v, nx;
  ll a, b;
} e[210];
int head[60], cnt;
ll c[60], d[60];
ll dis[60][3000];
void add(int u, int v, ll a, ll b) {
  e[++cnt].v = v;
  e[cnt].a = a;
  e[cnt].b = b;
  e[cnt].nx = head[u];
  head[u] = cnt;
}
struct node {
  int u;
  ll s, t;
  bool operator<(const node &x) const { return t > x.t; }
};
ll dis1[100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int n, m;
  ll s;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    add(u, v, a, b);
    add(v, u, a, b);
  }
  for (int i = 1; i <= n; i++)
    cin >> c[i] >> d[i];
  if (s > 2500) {
    for (int i = 1; i <= n; i++)
      dis1[i] = inf * inf;
    dis1[1] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push(mp(0, 1));
    while (!q.empty()) {
      pii p = q.top();
      q.pop();
      int u = p.se;
      if (dis1[u] < p.fi)
        continue;
      for (int i = head[u]; i; i = e[i].nx) {
        int v = e[i].v;
        if (dis1[v] > dis1[u] + e[i].b) {
          dis1[v] = dis1[u] + e[i].b;
          q.push(mp(dis1[v], v));
        }
      }
    }
    for (int i = 2; i <= n; i++)
      cout << dis1[i] << endl;
    return 0;
  }
  priority_queue<node> q;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 50 * n; j++)
      dis[i][j] = 1e18;
  dis[1][s] = 0;
  q.push((node){1, s, 0});
  while (!q.empty()) {
    node p = q.top();
    q.pop();
    int u = p.u;
    if (p.t > dis[u][p.s])
      continue;
    for (int i = head[u]; i; i = e[i].nx) {
      int v = e[i].v;
      if (p.s >= e[i].a && dis[v][p.s - e[i].a] > dis[u][p.s] + e[i].b) {
        dis[v][p.s - e[i].a] = dis[u][p.s] + e[i].b;
        q.push((node){v, p.s - e[i].a, dis[u][p.s] + e[i].b});
      }
    }
    ll ts = min(p.s + c[u], 50ll * n);
    if (dis[u][ts] > dis[u][p.s] + d[u]) {
      dis[u][ts] = dis[u][p.s] + d[u];
      q.push((node){u, ts, dis[u][p.s] + d[u]});
    }
  }
  for (int i = 2; i <= n; i++) {
    ll ans = 1e18;
    for (int j = 0; j <= 50 * n; j++)
      ans = min(ans, dis[i][j]);
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
// const int mod=998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

struct edge {
  int v, nx;
  ll a, b;
} e[110];
int head[60], cnt;
ll c[60], d[60];
ll dis[60][3000];
void add(int u, int v, ll a, ll b) {
  e[++cnt].v = v;
  e[cnt].a = a;
  e[cnt].b = b;
  e[cnt].nx = head[u];
  head[u] = cnt;
}
struct node {
  int u;
  ll s, t;
  bool operator<(const node &x) const { return t > x.t; }
};
ll dis1[100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int n, m;
  ll s;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    add(u, v, a, b);
    add(v, u, a, b);
  }
  for (int i = 1; i <= n; i++)
    cin >> c[i] >> d[i];
  if (s > 2500) {
    for (int i = 1; i <= n; i++)
      dis1[i] = inf * inf;
    dis1[1] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push(mp(0, 1));
    while (!q.empty()) {
      pii p = q.top();
      q.pop();
      int u = p.se;
      if (dis1[u] < p.fi)
        continue;
      for (int i = head[u]; i; i = e[i].nx) {
        int v = e[i].v;
        if (dis1[v] > dis1[u] + e[i].b) {
          dis1[v] = dis1[u] + e[i].b;
          q.push(mp(dis1[v], v));
        }
      }
    }
    for (int i = 2; i <= n; i++)
      cout << dis1[i] << endl;
    return 0;
  }
  priority_queue<node> q;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 50 * n; j++)
      dis[i][j] = inf * inf;
  dis[1][s] = 0;
  q.push((node){1, s, 0});
  while (!q.empty()) {
    node p = q.top();
    q.pop();
    int u = p.u;
    if (p.t > dis[u][p.s])
      continue;
    for (int i = head[u]; i; i = e[i].nx) {
      int v = e[i].v;
      if (p.s >= e[i].a && dis[v][p.s - e[i].a] > dis[u][p.s] + e[i].b) {
        dis[v][p.s - e[i].a] = dis[u][p.s] + e[i].b;
        q.push((node){v, p.s - e[i].a, dis[u][p.s] + e[i].b});
      }
    }
    if (p.s <= 50 * n && dis[u][p.s + c[u]] > dis[u][p.s] + d[u]) {
      dis[u][p.s + c[u]] = dis[u][p.s] + d[u];
      q.push((node){u, p.s + c[u], dis[u][p.s] + d[u]});
    }
  }
  for (int i = 2; i <= n; i++) {
    ll ans = inf;
    for (int j = 0; j <= 50 * n; j++)
      ans = min(ans, dis[i][j]);
    cout << ans << endl;
  }
  return 0;
}