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

// raja1999

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define int ll

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

// std::ios::sync_with_stdio(false);

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

// raja1999

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pll
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<ll, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<tri, vector<tri>, greater<tri>>

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

// std::ios::sync_with_stdio(false);
pdqueue pq;
ll c[55], d[55], dist[55][3005];
vector<vl> adj(55), cost(55), wt(55);
pii par[55][3005];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  double clk = clock();
  ll n, m, s, u, v, a, b, i, j, dis, x, y, ans, y1;
  tri p;
  cin >> n >> m >> s;
  rep(i, m) {
    cin >> u >> v >> a >> b;
    u--;
    v--;
    adj[u].pb(v);
    adj[v].pb(u);
    cost[u].pb(a);
    cost[v].pb(a);
    wt[u].pb(b);
    wt[v].pb(b);
  }
  rep(i, n) { cin >> c[i] >> d[i]; }
  s = min(s, 2502LL);
  ll iinf = inf;
  iinf *= inf;
  rep(i, n) {
    rep(j, 2503) { dist[i][j] = iinf; }
  }
  dist[0][s] = 0;
  pq.push(mp(dist[0][s], mp(0, s)));
  while (!pq.empty()) {
    p = pq.top();
    dis = p.ff;
    x = p.ss.ff;
    y = p.ss.ss;
    pq.pop();
    if (dist[x][y] < dis) {
      continue;
    }
    rep(i, adj[x].size()) {
      if (y >= cost[x][i]) {
        if (dist[adj[x][i]][y - cost[x][i]] > dis + wt[x][i]) {
          par[adj[x][i]][y - cost[x][i]] = mp(x, y);
          dist[adj[x][i]][y - cost[x][i]] = dis + wt[x][i];
          pq.push(mp(dist[adj[x][i]][y - cost[x][i]],
                     mp(adj[x][i], y - cost[x][i])));
        }
      }
    }
    y1 = y;
    dis += d[x];
    y += c[x];
    while (y < 2503) {
      if (dist[x][y] > dis) {
        par[x][y] = mp(x, y1);
        dist[x][y] = dis;
        pq.push(mp(dis, mp(x, y)));
      }
      dis += d[x];
      y += c[x];
    }
  }
  // cout<<dist[0][3]<<endl;
  f(i, 1, n) {
    ans = iinf;
    rep(j, 2503) { ans = min(ans, dist[i][j]); }
    cout << ans << endl;
  }
  // cerr<<(clock()-clk)/CLOCKS_PER_SEC<<endl;
  return 0;
}