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

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

struct point {

  ll p; // point
  ll s; // silver

  bool operator<(const point rhs) const {
    if (p != rhs.p) {
      return p < rhs.p;
    } else {
      return s < rhs.s;
    }
  }
};

int main() {
  ll n, m, s;
  std::cin >> n >> m >> s;

  vector<ll> u(m), v(m), a(m), b(m), c(n), d(n);
  vector<vector<pair<point, ll>>> edges(2500 * 53);

  ll amx = 0;
  for (int i = 0; i < m; i++) {
    std::cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    amx = max(amx, a[i]);
    for (int j = 0; j <= 2500; j++) {
      if (j - a[i] < 0)
        continue;
      edges[u[i] + 50 * j].push_back({{v[i], j - a[i]}, b[i]});
      edges[v[i] + 50 * j].push_back({{u[i], j - a[i]}, b[i]});
    }
  }

  for (int i = 0; i < n; i++) {
    std::cin >> c[i] >> d[i];
    for (int j = 0; j <= 2500; j++) {
      // std::cout << j << std::endl;
      edges[i + 50 * j].push_back({{i, j + c[i]}, d[i]});
      if ((j + c[i]) >= 2500)
        break;
    }
  }
  s = min(s, amx * n);

  typedef pair<ll, point> P;
  // map<point,ll> dd;
  vector<vector<ll>> dd(n, vector<ll>(2510, 1e18));
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, {0, s}});
  for (int i = 0; i <= s; i++) {
    dd[0][i] = 0;
  }

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    point v = p.second;
    if (dd[v.p][min(2500ll, v.s)] < p.first)
      continue;

    for (auto e : edges[v.p + 50 * min(2500ll, v.s)]) {
      auto [po, co] = e;
      if (dd[po.p][min(2500ll, po.s)] > dd[v.p][min(2500ll, v.s)] + co) {
        dd[po.p][min(2500ll, po.s)] = dd[v.p][min(2500ll, v.s)] + co;
        que.push({dd[po.p][min(2500ll, po.s)], po});
      }
    }
  }

  for (int i = 1; i < n; i++) {
    ll tmp = 1e18;
    for (int j = 0; j <= amx * n; j++) {
      tmp = min(tmp, dd[i][j]);
    }
    std::cout << tmp << std::endl;
  }
}


Error: -11

Fixed submission:

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

struct point {

  ll p; // point
  ll s; // silver

  bool operator<(const point rhs) const {
    if (p != rhs.p) {
      return p < rhs.p;
    } else {
      return s < rhs.s;
    }
  }
};

int main() {
  ll n, m, s;
  std::cin >> n >> m >> s;

  vector<ll> u(m), v(m), a(m), b(m), c(n), d(n);
  vector<vector<pair<point, ll>>> edges(2500 * 53);

  ll amx = 0;
  for (int i = 0; i < m; i++) {
    std::cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    amx = max(amx, a[i]);
    for (int j = 0; j <= 2500; j++) {
      if (50 * j - a[i] < 0)
        continue;
      edges[u[i] + 50 * j].push_back({{v[i], j - a[i]}, b[i]});
      edges[v[i] + 50 * j].push_back({{u[i], j - a[i]}, b[i]});
    }
  }

  for (int i = 0; i < n; i++) {
    std::cin >> c[i] >> d[i];
    for (int j = 0; j <= 2500; j++) {
      // std::cout << j << std::endl;
      edges[i + 50 * j].push_back({{i, j + c[i]}, d[i]});
      if ((j + c[i]) >= 2500)
        break;
    }
  }
  s = min(s, amx * n);

  typedef pair<ll, point> P;
  // map<point,ll> dd;
  vector<vector<ll>> dd(n, vector<ll>(2510, 1e18));
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, {0, s}});
  for (int i = 0; i <= s; i++) {
    dd[0][i] = 0;
  }

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    point v = p.second;
    if (dd[v.p][min(2500ll, v.s)] < p.first)
      continue;

    for (auto e : edges[v.p + 50 * min(2500ll, v.s)]) {
      auto [po, co] = e;
      if (dd[po.p][min(2500ll, po.s)] > dd[v.p][min(2500ll, v.s)] + co) {
        dd[po.p][min(2500ll, po.s)] = dd[v.p][min(2500ll, v.s)] + co;
        que.push({dd[po.p][min(2500ll, po.s)], po});
      }
    }
  }

  for (int i = 1; i < n; i++) {
    ll tmp = 1e18;
    for (int j = 0; j <= amx * n; j++) {
      tmp = min(tmp, dd[i][j]);
    }
    std::cout << tmp << std::endl;
  }
}