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

/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define int ll
#define forn(i, n) for (int i = 0; i < n; i++)
#define rforn(i, n) for (int i = n - 1; i >= 0; i--)
#define forne(i, n) for (int i = 1; i <= n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define rforse(i, s, e) for (int i = e - 1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a, x) memset(a, x, sizeof a);
#define trav(a, x) for (auto &a : x)
#define INF int(1e17)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
  a %= m;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
ll bpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll modinv(ll a) { return modpow(a, MOD - 2, MOD); }
void graph(vvi &adj, int m) {
  int x, y;
  forn(i, m) {
    cin >> x >> y;
    adj[x - 1].pb(y - 1);
    adj[y - 1].pb(x - 1);
  }
}

const int mxM = 25e2, mxN = 50;
typedef vector<vector<pair<int, pii>>> vvpiii;
typedef pair<int, pii> ppii;
vector<pii> city(mxN);
int n, m, s;
ll dist[50][mxM + 5];
void djik(vvpiii &adj) {
  priority_queue<ppii> q;
  q.push({0, {0, s}});
  while (!q.empty()) {
    ppii cur = q.top();
    q.pop();
    int cit = cur.S.F, dis = -cur.F, stat = cur.S.S;
    trace(cit, dis, stat);
    if (dist[cit][stat] < dis)
      continue;
    trav(to, adj[cit]) {
      int edge = to.S.S, silver = to.S.F;
      if (stat >= silver && dist[to.F][stat - silver] > edge + dis) {
        dist[to.F][stat - silver] = edge + dis;
        q.push({-(edge + dis), {to.F, stat - silver}});
      }
    }
    if (stat + city[cit].F <= mxM &&
        dist[cit][stat + city[cit].F] > city[cit].S + dis) {
      dist[cit][stat + city[cit].F] = city[cit].S + dis;
      q.push({-(city[cit].S + dis), {cit, stat + city[cit].F}});
    }
  }
}

void solve() {
  cin >> n >> m >> s;
  s = min(s, mxM);
  vvpiii adj(n);
  int u, v, a, b;
  forn(i, m) {
    cin >> u >> v >> a >> b;
    u--, v--;
    adj[u].pb({v, {a, b}});
    adj[v].pb({u, {a, b}});
  }
  forn(i, n) forn(j, mxM) dist[i][j] = INF;
  forn(i, n) cin >> city[i].F >> city[i].S;
  djik(adj);
  forne(i, n - 1) {
    int minm = INF;
    forn(j, mxM) minm = min(minm, dist[i][j]);
    cout << minm << '\\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifdef SHUBHAM107
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}


Error: 0

Fixed submission:

/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define int ll
#define forn(i, n) for (int i = 0; i < n; i++)
#define rforn(i, n) for (int i = n - 1; i >= 0; i--)
#define forne(i, n) for (int i = 1; i <= n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define rforse(i, s, e) for (int i = e - 1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a, x) memset(a, x, sizeof a);
#define trav(a, x) for (auto &a : x)
#define INF int(1e17)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
  a %= m;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
ll bpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll modinv(ll a) { return modpow(a, MOD - 2, MOD); }
void graph(vvi &adj, int m) {
  int x, y;
  forn(i, m) {
    cin >> x >> y;
    adj[x - 1].pb(y - 1);
    adj[y - 1].pb(x - 1);
  }
}

const int mxM = 25e2, mxN = 50;
typedef vector<vector<pair<int, pii>>> vvpiii;
typedef pair<int, pii> ppii;
vector<pii> city(mxN);
int n, m, s;
ll dist[50][mxM + 5];
void djik(vvpiii &adj) {
  priority_queue<ppii> q;
  q.push({0, {0, s}});
  while (!q.empty()) {
    ppii cur = q.top();
    q.pop();
    int cit = cur.S.F, dis = -cur.F, stat = cur.S.S;
    trace(cit, dis, stat);
    if (dist[cit][stat] < dis)
      continue;
    trav(to, adj[cit]) {
      int edge = to.S.S, silver = to.S.F;
      if (stat >= silver && dist[to.F][stat - silver] > edge + dis) {
        dist[to.F][stat - silver] = edge + dis;
        q.push({-(edge + dis), {to.F, stat - silver}});
      }
    }
    if (dist[cit][stat + city[cit].F] > city[cit].S + dis) {
      dist[cit][stat + city[cit].F] = city[cit].S + dis;
      q.push({-(city[cit].S + dis), {cit, stat + city[cit].F}});
    }
  }
}

void solve() {
  cin >> n >> m >> s;
  s = min(s, mxM);
  vvpiii adj(n);
  int u, v, a, b;
  forn(i, m) {
    cin >> u >> v >> a >> b;
    u--, v--;
    adj[u].pb({v, {a, b}});
    adj[v].pb({u, {a, b}});
  }
  forn(i, n) forn(j, mxM) dist[i][j] = INF;
  forn(i, n) cin >> city[i].F >> city[i].S;
  djik(adj);
  forne(i, n - 1) {
    int minm = INF;
    forn(j, mxM) minm = min(minm, dist[i][j]);
    cout << minm << '\\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifdef SHUBHAM107
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}