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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\\n'
#define po(x) (1ll << x)
const ll DIM = 50 + 7;
const ll INF = 10E17;
struct node {
  ll fi, sc, th;
};
vector<node> G[DIM];
ll C[DIM], D[DIM], dp[DIM][10007];
const bool operator>(const node &a, const node &b) { return a.fi > b.fi; }
int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, m, ss;
  cin >> n >> m >> ss;
  ll sum = 0;
  forn(i, m) {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    sum += a;
    G[x].pb({y, a, b});
    G[y].pb({x, a, b});
  }
  forn(i, n) cin >> C[i] >> D[i];
  memset(dp, -1, sizeof(dp));
  priority_queue<node, vector<node>, greater<node>> Q;
  sum *= 2;
  ss = min(ss, sum);
  Q.push({0, 1, ss});
  dp[1][ss] = 0;

  while (!Q.empty()) {
    pp t = {Q.top().sc, Q.top().th};
    // cout<<dp[t.fi][t.sc]<<endl;
    Q.pop();
    if (C[t.fi] + t.sc <= sum &&
        (dp[t.fi][t.sc + C[t.fi]] == -1 ||
         dp[t.fi][t.sc + C[t.fi]] > dp[t.fi][t.sc] + D[t.fi])) {
      dp[t.fi][t.sc + C[t.fi]] = dp[t.fi][t.sc] + D[t.fi];
      Q.push({dp[t.fi][t.sc + C[t.fi]], t.fi, t.sc + C[t.fi]});
    }
    for (node to : G[t.fi]) {
      if (to.sc > t.sc)
        continue;
      if (dp[to.fi][t.sc - to.sc] == -1 ||
          dp[to.fi][t.sc - to.sc] > dp[t.fi][t.sc] + to.th) {
        dp[to.fi][t.sc - to.sc] = dp[t.fi][t.sc] + to.th;
        Q.push({dp[to.fi][t.sc - to.sc], to.fi, t.sc - to.sc});
      }
    }
  }
  for (ll i = 2; i <= n; ++i) {
    ll res = INF;
    for (ll j = 0; j <= sum; ++j) {
      if (dp[i][j] != -1)
        res = min(res, dp[i][j]);
    }
    cout << res << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\\n'
#define po(x) (1ll << x)
const ll DIM = 50 + 7;
const ll INF = 10E17;
struct node {
  ll fi, sc, th;
};
vector<node> G[DIM];
ll C[DIM], D[DIM], dp[DIM][10007];
const bool operator>(const node &a, const node &b) { return a.fi > b.fi; }
int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, m, ss;
  cin >> n >> m >> ss;
  ll sum = 0;
  forn(i, m) {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    sum += a;
    G[x].pb({y, a, b});
    G[y].pb({x, a, b});
  }
  forn(i, n) cin >> C[i] >> D[i];
  memset(dp, -1, sizeof(dp));
  priority_queue<node, vector<node>, greater<node>> Q;
  Q.push({0, 1, ss});
  dp[1][ss] = 0;
  sum *= 2;
  while (!Q.empty()) {
    pp t = {Q.top().sc, Q.top().th};
    // cout<<dp[t.fi][t.sc]<<endl;
    Q.pop();
    if (C[t.fi] + t.sc <= sum &&
        (dp[t.fi][t.sc + C[t.fi]] == -1 ||
         dp[t.fi][t.sc + C[t.fi]] > dp[t.fi][t.sc] + D[t.fi])) {
      dp[t.fi][t.sc + C[t.fi]] = dp[t.fi][t.sc] + D[t.fi];
      Q.push({dp[t.fi][t.sc + C[t.fi]], t.fi, t.sc + C[t.fi]});
    }
    for (node to : G[t.fi]) {
      if (to.sc > t.sc)
        continue;
      if (dp[to.fi][t.sc - to.sc] == -1 ||
          dp[to.fi][t.sc - to.sc] > dp[t.fi][t.sc] + to.th) {
        dp[to.fi][t.sc - to.sc] = dp[t.fi][t.sc] + to.th;
        Q.push({dp[to.fi][t.sc - to.sc], to.fi, t.sc - to.sc});
      }
    }
  }
  for (ll i = 2; i <= n; ++i) {
    ll res = INF;
    for (ll j = 0; j <= sum; ++j) {
      if (dp[i][j] != -1)
        res = min(res, dp[i][j]);
    }
    cout << res << endl;
  }
  return 0;
}