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

#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll MOD = 1000000007;

struct node {
  vector<int> link;
  vector<ll> a;
  vector<ll> b;
  vector<ll> s;
};

ll inf = 1e18;
ll N, M, S;
ll amax;
vector<node> nod;
int main() {
  cin >> N >> M >> S;
  nod.resize(N);
  amax = 0;
  rep(i, M) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    nod[u].link.emplace_back(v);
    nod[v].link.emplace_back(u);
    nod[u].a.push_back(a);
    nod[u].b.push_back(b);
    nod[v].a.push_back(a);
    nod[v].b.push_back(b);
    amax = max(amax, a);
  }
  rep(i, N) {
    ll c, d;
    cin >> c >> d;
    nod[i].link.emplace_back(i);
    nod[i].a.push_back(-c);
    nod[i].b.push_back(d);
    nod[i].s.resize(amax * (N - 1) + 1);
    rep(j, amax * (N - 1) + 1) nod[i].s[j] = inf;
  }
  queue<ll> nq;
  queue<ll> sq;
  ll st = min(S, amax * (N - 1));
  nod[0].s[st] = 0;
  nq.push(0);
  sq.push(st);
  while (!nq.empty()) {
    ll n = nq.front();
    ll s = sq.front();
    nq.pop();
    sq.pop();
    rep(i, nod[n].link.size()) {
      if (s - nod[n].a[i] < 0)
        continue;
      ll ns = min(s - nod[n].a[i], amax * (N - 1));
      ll nt = nod[n].s[s] + nod[n].b[i];
      ll nn = nod[n].link[i];
      if (nod[nn].s[ns] > nt) {
        nod[nn].s[ns] = nt;
        nq.push(nn);
        sq.push(ns);
      }
    }
  }
  repi(i, 1, N) {
    ll res = inf;
    rep(j, nod[i].s.size()) res = min(res, nod[i].s[j]);
    cout << res << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll MOD = 1000000007;

struct node {
  vector<int> link;
  vector<ll> a;
  vector<ll> b;
  vector<ll> s;
};

ll inf = 1e18;
ll N, M, S;
ll amax;
vector<node> nod;
int main() {
  cin >> N >> M >> S;
  nod.resize(N);
  amax = 0;
  rep(i, M) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    nod[u].link.emplace_back(v);
    nod[v].link.emplace_back(u);
    nod[u].a.push_back(a);
    nod[u].b.push_back(b);
    nod[v].a.push_back(a);
    nod[v].b.push_back(b);
    amax = max(amax, a);
  }
  rep(i, N) {
    ll c, d;
    cin >> c >> d;
    nod[i].link.emplace_back(i);
    nod[i].a.push_back(-c);
    nod[i].b.push_back(d);
    nod[i].s.resize(amax * (N - 1) + 1);
    rep(j, amax * (N - 1) + 1) nod[i].s[j] = inf;
  }
  queue<ll> nq;
  queue<ll> sq;
  nod[0].s[S] = 0;
  nq.push(0);
  sq.push(S);
  while (!nq.empty()) {
    ll n = nq.front();
    ll s = sq.front();
    nq.pop();
    sq.pop();
    rep(i, nod[n].link.size()) {
      if (s - nod[n].a[i] < 0)
        continue;
      ll ns = min(s - nod[n].a[i], amax * (N - 1));
      ll nt = nod[n].s[s] + nod[n].b[i];
      ll nn = nod[n].link[i];
      if (nod[nn].s[ns] > nt) {
        nod[nn].s[ns] = nt;
        nq.push(nn);
        sq.push(ns);
      }
    }
  }
  repi(i, 1, N) {
    ll res = inf;
    rep(j, nod[i].s.size()) res = min(res, nod[i].s[j]);
    cout << res << endl;
  }
  return 0;
}