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

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

ll pm[55];
ll pc[55];

int prevv[100010]; // 頂点の最大数
struct edge {
  int to;
  int money;
  ll cost; //=time
};

vector<vector<ll>> dijkstra(int n, vector<vector<edge>> G, int sv, int sm) {
  fill(prevv, prevv + n, -1);
  priority_queue<tlll, vector<tlll>, greater<tlll>> que;
  vector<vector<ll>> dist(n, vector<ll>(2500, lnf));
  dist[sv][sm] = 0;
  que.push(tlll(0, sv, sm));
  while (!que.empty()) {
    ll cost, m;
    int v;
    tie(cost, v, m) = que.top();
    que.pop();
    if (dist[v][m] < cost)
      continue;
    if (m + pm[v] < 2500) { // 一回のみ補充
      ll nm = m + pm[v];
      ll nc = cost + pc[v];
      if (dist[v][nm] > nc) {
        dist[v][nm] = nc;
        que.push(tlll(dist[v][nm], v, nm));
      }
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      ll ec = e.cost;
      ll nm = m - e.money;
      int nv = e.to;
      if (nm >= 0 && dist[nv][nm] > dist[v][m] + ec) {
        dist[nv][nm] = dist[v][m] + ec;
        prevv[nv] = v;
        que.push(tlll(dist[nv][nm], nv, nm));
      }
    }
  }
  return dist;
}

// 頂点への最短路
vector<int> get_path(int t) {
  vector<int> path(0);
  for (; t != -1; t = prevv[t])
    path.push_back(t);
  reverse(path.begin(), path.end());
  return path;
}

int main() {
  itn n, m, s;
  cin >> n >> m >> s;
  if (s >= 2500)
    s = 2499;
  vector<vector<edge>> g(n, vector<edge>(0));
  rep(i, m) {
    itn u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, a, b});
    g[v].push_back({u, a, b});
  }
  rep(i, n) {
    itn c, d;
    cin >> c >> d;
    pm[i] = c;
    pc[i] = d;
  }
  vector<vector<ll>> dist = dijkstra(n, g, 0, s);
  vector<ll> ans(n, lnf);
  rep(i, n) rep(j, 2500) { chmin(ans[i], dist[i][j]); }
  rep1(i, n - 1) cout << ans[i] << endl;
}

Error: 0

Fixed submission:

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
const ll lnf = 1ll << 60;

ll pm[55];
ll pc[55];

int prevv[100010]; // 頂点の最大数
struct edge {
  int to;
  int money;
  ll cost; //=time
};

vector<vector<ll>> dijkstra(int n, vector<vector<edge>> G, int sv, int sm) {
  fill(prevv, prevv + n, -1);
  priority_queue<tlll, vector<tlll>, greater<tlll>> que;
  vector<vector<ll>> dist(n, vector<ll>(2500, lnf));
  dist[sv][sm] = 0;
  que.push(tlll(0, sv, sm));
  while (!que.empty()) {
    ll cost, m;
    int v;
    tie(cost, v, m) = que.top();
    que.pop();
    if (dist[v][m] < cost)
      continue;
    if (m + pm[v] < 2500) { // 一回のみ補充
      ll nm = m + pm[v];
      ll nc = cost + pc[v];
      if (dist[v][nm] > nc) {
        dist[v][nm] = nc;
        que.push(tlll(dist[v][nm], v, nm));
      }
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      ll ec = e.cost;
      ll nm = m - e.money;
      int nv = e.to;
      if (nm >= 0 && dist[nv][nm] > dist[v][m] + ec) {
        dist[nv][nm] = dist[v][m] + ec;
        prevv[nv] = v;
        que.push(tlll(dist[nv][nm], nv, nm));
      }
    }
  }
  return dist;
}

// 頂点への最短路
vector<int> get_path(int t) {
  vector<int> path(0);
  for (; t != -1; t = prevv[t])
    path.push_back(t);
  reverse(path.begin(), path.end());
  return path;
}

int main() {
  itn n, m, s;
  cin >> n >> m >> s;
  vector<vector<edge>> g(n, vector<edge>(0));
  rep(i, m) {
    itn u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, a, b});
    g[v].push_back({u, a, b});
  }
  rep(i, n) {
    itn c, d;
    cin >> c >> d;
    pm[i] = c;
    pc[i] = d;
  }
  vector<vector<ll>> dist = dijkstra(n, g, 0, s);
  vector<ll> ans(n, lnf);
  rep(i, n) rep(j, 2500) { chmin(ans[i], dist[i][j]); }
  rep1(i, n - 1) cout << ans[i] << endl;
}