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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e16;
const int MAXN = 69, MAXS = 25e2 + 69;
struct vl {
  int x, y, z;
  bool operator<(const vl &oth) const {
    if (x == oth.x && y == oth.y)
      return z < oth.z;
    if (x == oth.x)
      return y < oth.y;
    return x < oth.x;
  }
};
int n, m, S;
vector<vl> g[MAXN];
vl shop[MAXN];
int kc[MAXN][MAXS];
void ditcha(int u) {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < MAXS; j++)
      kc[i][j] = INF;
  }
  set<vl> s;
  int i = 0;
  while (1) {
    int c = S + i * shop[u].x, br = 0;
    if (c >= MAXS - 1)
      br = 1, c = MAXS - 1;
    kc[u][c] = i * shop[u].y;
    s.insert({kc[u][c], u, c});
    i++;
    if (br)
      break;
  }
  while (!s.empty()) {
    int u = (*s.begin()).y;
    int c = (*s.begin()).z;
    s.erase(s.begin());
    for (vl i : g[u]) {
      int v = i.x, a = i.y, b = i.z;
      if (c - a < 0)
        continue;
      int j = 0;
      while (1) {
        int d = c - a + j * shop[v].x, br = 0;
        if (d >= MAXS - 1)
          br = 1, d = MAXS - 1;
        if (kc[v][d] > kc[u][c] + b + j * shop[v].y) {
          if (kc[v][d] != INF)
            s.erase({kc[v][d], v, d});
          kc[v][d] = kc[u][c] + b + j * shop[v].y;
          s.insert({kc[v][d], v, d});
        }
        j++;
        if (br)
          break;
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> S;
  for (int i = 1, u, v, a, b; i <= m; i++) {
    cin >> u >> v >> a >> b;
    g[u].push_back({v, a, b});
    g[v].push_back({u, a, b});
  }
  for (int i = 1; i <= n; i++)
    cin >> shop[i].x >> shop[i].y;
  ditcha(1);
  for (int v = 2; v <= n; v++) {
    int res = INF;
    for (int i = 0; i < MAXS; i++)
      res = min(res, kc[v][i]);
    cout << res << '\\n';
  }
}

Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 55;
const int M = 3005;
const int inf = 0x3f3f3f3f;
const int mod = 300;
const double eps = 1e-9;
const long double pi = acos(-1.0L);
#define ls (i << 1)
#define rs (i << 1 | 1)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define mem(a, b) memset(a, b, sizeof(a))
LL read() {
  LL x = 0, t = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      t = -1;
  while (isdigit(ch)) {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * t;
}
struct edge {
  int t, c, v;
  edge() {}
  edge(int V, int T, int C) {
    v = V;
    t = T;
    c = C;
  }
};
struct node {
  int id, co, disx;
  node() {}
  node(int T, int C, int D) {
    id = T;
    co = C;
    disx = D;
  }
  friend bool operator<(node x, node y) { return x.disx > y.disx; }
};
int vis[N][M], dis[N][M], n, m, s;
priority_queue<node, vector<node>, less<node>> q;
vector<edge> e[N];
void dijk() {
  mem(dis, 0x3f);
  dis[1][s] = 0;
  q.push(node(1, s, 0));
  while (!q.empty()) {
    node u = q.top();
    q.pop();
    if (vis[u.id][u.co])
      continue;
    vis[u.id][u.co] = 1;
    for (auto x : e[u.id]) {
      // puts("...");
      if (x.c + u.co >= 0 && x.c + u.co <= 2600 &&
          dis[x.v][x.c + u.co] > dis[u.id][u.co] + x.t) {
        // printf("-- %d %d\\n",x.v,x.c+u.co);
        dis[x.v][x.c + u.co] = dis[u.id][u.co] + x.t;
        q.push(node(x.v, x.c + u.co, dis[x.v][x.c + u.co]));
      }
    }
  }
}
int main() {
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), c = read(), t = read();
    e[u].pb(edge(v, t, -c));
    e[v].pb(edge(u, t, -c));
  }
  for (int i = 1; i <= n; i++) {
    int c = read(), t = read();
    e[i].pb(edge(i, t, c));
  }
  dijk();
  for (int i = 2; i <= n; i++) {
    int mi = inf;
    for (int j = 0; j <= 2500; j++)
      mi = min(dis[i][j], mi);
    printf("%d\\n", mi);
  }
  return 0;
}