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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, s;
ll sum;
class V {
public:
  ll to, cost, time;

public:
  V(ll to, ll cost, ll time) {
    this->to = to;
    this->cost = cost;
    this->time = time;
  }
};
vector<V> G[50];
ll C[50], D[50];
ll DIS[50][2501];
const ll INF = 1e18;

class P {
public:
  ll v, time, gin;

public:
  P(ll v, ll time, ll gin) {
    this->v = v;
    this->time = time;
    this->gin = gin;
  }
};
bool operator<(const P &a, const P &b) { return a.time > b.time; }

void dijkstra(ll gin) {

  priority_queue<P> PQ;
  PQ.emplace(0, 0, min(0LL + 2500, gin));
  DIS[0][min(0LL + 2500, gin)] = 0;
  /*
  for(ll i = 0 ;;i++)
  {
          if(gin+i*C[0]>2500)
          {
                  DIS[0][2500] = i*D[0];
                  PQ.emplace(0,DIS[0][2500],2500);
                  break;
          }
                  DIS[0][gin+i*C[0]] = i*D[0];
                  PQ.emplace(0,DIS[0][gin+i*C[0]],gin+i*C[0]);
  }
  */
  while (!PQ.empty()) {
    // cout<<PQ.size()<<endl;
    auto now = PQ.top();
    ll v = now.v;
    PQ.pop();

    // cout<<v<<endl;
    // 今交換できる分交換する；
    if (DIS[v][now.gin] < now.time)
      continue;
    for (ll i = 1; i < 2; ++i) {
      if (now.gin + i * C[v] > 2500) {

        if (DIS[v][2500] > now.time + i * D[v]) {
          DIS[v][2500] = now.time + i * D[v];
          PQ.emplace(v, DIS[v][2500], 2500);
        }
        break;
      }
      if (DIS[v][now.gin + i * C[v]] > now.time + i * D[v]) {
        DIS[v][now.gin + i * C[v]] = now.time + i * D[v];
        PQ.emplace(v, DIS[v][now.gin + i * C[v]], now.gin + i * C[v]);
      }
    }
    for (auto &next : G[v]) {
      //	if(v==0&&now.time==10)cout<<';'<<next.to<<'
      //'<<now.time+next.time<<' '<<gin<<endl
      //	<<DIS[next.to][now.gin-next.cost]<<endl;
      if (now.gin - next.cost < 0)
        continue;
      if (DIS[next.to][now.gin - next.cost] > now.time + next.time) {
        DIS[next.to][now.gin - next.cost] = now.time + next.time;
        PQ.emplace(next.to, DIS[next.to][now.gin - next.cost],
                   now.gin - next.cost);
      }
    }
  }
}

int main() {
  for (ll i = 0; i < 50; i++) {
    for (ll j = 0; j < 2501; j++) {
      DIS[i][j] = INF;
    }
  }
  cin >> n >> m >> s;
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].emplace_back(v, a, b);
    G[v].emplace_back(u, a, b);
    sum += a;
  }

  for (ll i = 0; i < n; ++i) {
    cin >> C[i] >> D[i];
  }
  dijkstra(s);
  for (ll i = 1; i < n; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2501; j++) {
      ans = min(ans, DIS[i][j]);
      // if(DIS[i][j]==15)cout<<';'<<j<<endl;
    }
    cout << ans << endl;
  }
  // cout<<DIS[2][0]<<endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, s;
ll sum;
class V {
public:
  ll to, cost, time;

public:
  V(ll to, ll cost, ll time) {
    this->to = to;
    this->cost = cost;
    this->time = time;
  }
};
vector<V> G[50];
ll C[50], D[50];
ll DIS[50][2501];
const ll INF = 1e18;

class P {
public:
  ll v, time, gin;

public:
  P(ll v, ll time, ll gin) {
    this->v = v;
    this->time = time;
    this->gin = gin;
  }
};
bool operator<(const P &a, const P &b) { return a.time > b.time; }

void dijkstra(ll gin) {

  priority_queue<P> PQ;
  PQ.emplace(0, 0, min(0LL + sum, gin));
  DIS[0][min(0LL + sum, gin)] = 0;
  /*
  for(ll i = 0 ;;i++)
  {
          if(gin+i*C[0]>sum)
          {
                  DIS[0][sum] = i*D[0];
                  PQ.emplace(0,DIS[0][sum],sum);
                  break;
          }
                  DIS[0][gin+i*C[0]] = i*D[0];
                  PQ.emplace(0,DIS[0][gin+i*C[0]],gin+i*C[0]);
  }
  */
  while (!PQ.empty()) {
    // cout<<PQ.size()<<endl;
    auto now = PQ.top();
    ll v = now.v;
    PQ.pop();

    // cout<<v<<endl;
    // 今交換できる分交換する；
    if (DIS[v][now.gin] < now.time)
      continue;
    for (ll i = 1;; ++i) {
      if (now.gin + i * C[v] > sum) {

        if (DIS[v][sum] > now.time + i * D[v]) {
          DIS[v][sum] = now.time + i * D[v];
          PQ.emplace(v, DIS[v][sum], sum);
        }
        break;
      }
      if (DIS[v][now.gin + i * C[v]] > now.time + i * D[v]) {
        DIS[v][now.gin + i * C[v]] = now.time + i * D[v];
        PQ.emplace(v, DIS[v][now.gin + i * C[v]], now.gin + i * C[v]);
      }
    }
    for (auto &next : G[v]) {
      //	if(v==0&&now.time==10)cout<<';'<<next.to<<'
      //'<<now.time+next.time<<' '<<gin<<endl
      //	<<DIS[next.to][now.gin-next.cost]<<endl;
      if (now.gin - next.cost < 0)
        continue;
      if (DIS[next.to][now.gin - next.cost] > now.time + next.time) {
        DIS[next.to][now.gin - next.cost] = now.time + next.time;
        PQ.emplace(next.to, DIS[next.to][now.gin - next.cost],
                   now.gin - next.cost);
      }
    }
  }
}

int main() {
  for (ll i = 0; i < 50; i++) {
    for (ll j = 0; j < 2501; j++) {
      DIS[i][j] = INF;
    }
  }
  cin >> n >> m >> s;
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].emplace_back(v, a, b);
    G[v].emplace_back(u, a, b);
    sum += a;
  }

  for (ll i = 0; i < n; ++i) {
    cin >> C[i] >> D[i];
  }
  dijkstra(s);
  for (ll i = 1; i < n; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2501; j++) {
      ans = min(ans, DIS[i][j]);
      // if(DIS[i][j]==15)cout<<';'<<j<<endl;
    }
    cout << ans << endl;
  }
  // cout<<DIS[2][0]<<endl;
}