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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 610;
int head[N];
ll c[N], d[N], dst[1000][3000];
struct node {
  int to;
  ll s, t;
  bool operator<(const node &f) const { return t > f.t; }
};
struct Edge {
  int to, next;
  ll t, s;
} e[N];
int cnt = 0;
void add(int u, int v, int s, int t) {
  e[++cnt].to = v;
  e[cnt].t = t;
  e[cnt].s = s;
  e[cnt].next = head[u];
  head[u] = cnt;
}
int main() {
  int n, m, u, v, s, ss, t;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> ss >> t;
    add(u, v, ss, t);
    add(v, u, ss, t);
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 2500; j++)
      dst[i][j] = 2e18;
  }
  if (s > 2500)
    s = 2500;
  priority_queue<node> q;
  q.push(node{1, s, 0});
  dst[1][s] = 0;
  while (!q.empty()) {
    //	cout<<"?";
    node on = q.top();
    q.pop();
    if (on.t > dst[on.to][on.s])
      continue;
    for (int i = head[on.to]; i; i = e[i].next) {
      if (on.s >= e[i].s) {
        int v = e[i].to;
        if (dst[v][on.s - e[i].s] > dst[on.to][on.s] + e[i].t) {
          dst[v][on.s - e[i].s] = dst[on.to][on.s] + e[i].t;
          q.push(node{v, on.s - e[i].s, dst[on.to][on.s] + e[i].t});
        }
      }
    }
    ll mx = min((ll)2500, on.s + c[on.to]);
    if (dst[on.to][mx] > dst[on.to][on.s] + d[on.to]) {
      dst[on.to][mx] = dst[on.to][on.s] + d[on.to];
      q.push(node{on.to, mx, dst[on.to][mx]});
    }
  }
  for (int i = 2; i <= n; i++) {
    ll mx = 2e18;
    for (int j = 0; j <= 2500; j++) {
      mx = min(mx, dst[i][j]);
    }
    cout << mx << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 410;
int head[N], vis[N];
ll c[N], d[N], dst[3000][3000];
struct node {
  int to;
  ll s, t;
  bool operator<(const node &f) const { return t > f.t; }
};
struct Edge {
  int to, next;
  ll t, s;
} e[N];
int cnt;
void add(int u, int v, int s, int t) {
  e[++cnt].to = v;
  e[cnt].t = t;
  e[cnt].s = s;
  e[cnt].next = head[u];
  head[u] = cnt;
}
int main() {
  int n, m, u, v, s, ss, t;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> ss >> t;
    add(u, v, ss, t);
    add(v, u, ss, t);
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 2500; j++)
      dst[i][j] = 2e18;
  }
  priority_queue<node> q;
  q.push(node{1, s, 0});
  dst[1][s] = 0;
  while (!q.empty()) {
    //	cout<<"?";
    node on = q.top();
    q.pop();
    if (on.t > dst[on.to][on.s])
      continue;
    for (int i = head[on.to]; i; i = e[i].next) {
      if (on.s >= e[i].s) {
        int v = e[i].to;
        if (dst[v][on.s - e[i].s] > dst[on.to][on.s] + e[i].t) {
          dst[v][on.s - e[i].s] = dst[on.to][on.s] + e[i].t;
          q.push(node{v, on.s - e[i].s, dst[on.to][on.s] + e[i].t});
        }
      }
    }
    ll mx = min((ll)2500, on.s + c[on.to]);
    if (dst[on.to][mx] > dst[on.to][on.s] + d[on.to]) {
      dst[on.to][mx] = dst[on.to][on.s] + d[on.to];
      q.push(node{on.to, mx, dst[on.to][mx]});
    }
  }
  for (int i = 2; i <= n; i++) {
    ll mx = 2e18;
    for (int j = 0; j <= 2500; j++) {
      mx = min(mx, dst[i][j]);
    }
    cout << mx << endl;
  }
}