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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

struct edge {
  long long to, cost;
};
using P = pair<int, int>;
int V;
const int MAX_V = 2e5 + 1;

vector<edge> G[MAX_V], newG[MAX_V]; // G[i]={j,c} ⇔ iからjへの辺の重みがc
vector<long long> d(MAX_V, INF / 2);

void dijkstra(int start) {
  priority_queue<P, vector<P>, greater<P>> que;
  d[start] = 0;
  que.push(P(0, start));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int toInt(pair<int, int> p) // 点とコインのペア
{
  return p.first * 2500 + p.second;
}
ll toInt(ll point, ll coin) { return point * 2500 + coin; }
int main() {
  int N, M, S;
  cin >> N >> M >> S;
  vint U(M), V(M), A(M), B(M);
  for (size_t i = 0; i < M; i++) {
    cin >> U[i] >> V[i] >> A[i] >> B[i];
    U[i]--;
    V[i]--;
    for (size_t j = A[i]; j < 2500; j++) {
      G[toInt(U[i], j)].push_back({toInt(V[i], j - A[i]), B[i]});
      G[toInt(V[i], j)].push_back({toInt(U[i], j - A[i]), B[i]});
    }
  }
  vint C(N), D(N);
  for (size_t i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
    for (ll j = 0; j + C[i] < 2500; j++) {
      G[toInt(i, j)].push_back({toInt(i, j + C[i]), D[i]});
    }
  }
  dijkstra(toInt(0, min(S, 2499)));
  for (size_t i = 1; i < N; i++) {
    ll ans = INF;
    for (size_t j = 0; j < 2500; j++) {
      chmin(ans, d[toInt(i, j)]);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

struct edge {
  long long to, cost;
};
using P = pair<int, int>;
int V;
const int MAX_V = 2e5 + 1;

vector<edge> G[MAX_V], newG[MAX_V]; // G[i]={j,c} ⇔ iからjへの辺の重みがc
vector<long long> d(MAX_V, INT_MAX);

void dijkstra(int start) {
  priority_queue<P, vector<P>, greater<P>> que;
  d[start] = 0;
  que.push(P(0, start));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int toInt(pair<int, int> p) // 点とコインのペア
{
  return p.first * 2500 + p.second;
}
int toInt(int point, int coin) { return point * 2500 + coin; }
int main() {
  int N, M, S;
  cin >> N >> M >> S;
  vint U(M), V(M), A(M), B(M);
  for (size_t i = 0; i < M; i++) {
    cin >> U[i] >> V[i] >> A[i] >> B[i];
    U[i]--;
    V[i]--;
    for (size_t j = A[i]; j < 2500; j++) {
      G[toInt(U[i], j)].push_back({toInt(V[i], j - A[i]), B[i]});
      G[toInt(V[i], j)].push_back({toInt(U[i], j - A[i]), B[i]});
    }
  }
  vint C(N), D(N);
  for (size_t i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
    for (ll j = 0; j + C[i] < 2500; j++) {
      G[toInt(i, j)].push_back({toInt(i, j + C[i]), D[i]});
    }
  }
  dijkstra(toInt(0, S));
  for (size_t i = 1; i < N; i++) {
    ll ans = INF;
    for (size_t j = 0; j < 2500; j++) {
      chmin(ans, d[toInt(i, j)]);
    }
    cout << ans << endl;
  }

  return 0;
}