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

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000000
#define MOD 10000007
#define MAXR 100000

#define PB push_back
#define VL vector<ll>

#define PQ priority_queue<VL, vector<VL>, greater<VL>>

#define MAXS ll(2999)

vector<VL> dijkstra(ll f, ll n, ll s, vector<vector<VL>> &edge) {

  s = min(s, MAXS);

  vector<VL> confirm(n, VL(MAXS + 1, false));

  vector<VL> mincost(n, VL(MAXS + 1, INF));
  mincost[f][s] = 0;

  PQ mincand;
  mincand.push({mincost[f][s], f, s});

  while (!mincand.empty()) {

    VL next = mincand.top();
    mincand.pop();

    if (confirm[next[1]][next[2]])
      continue;

    confirm[next[1]][next[2]] = true;

    vector<VL> &v = edge[next[1]];
    ll l = SIZE(v);
    REP(i, l) {

      ll nextS = min(next[2] + v[i][1], MAXS);

      if (nextS < 0)
        continue;

      if (mincost[v[i][0]][nextS] <= next[0] + v[i][2])
        continue;

      mincost[v[i][0]][nextS] = next[0] + v[i][2];
      mincand.push({mincost[v[i][0]][nextS], v[i][0], nextS});
    }
  }
  return mincost;
}

signed main() {
  ll n, m, s;
  cin >> n >> m >> s;

  vector<vector<VL>> edge(n);
  REP(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    edge[u - 1].PB({v - 1, -a, b});
    edge[v - 1].PB({u - 1, -a, b});
  }
  REP(i, n) {
    ll c, d;
    cin >> c >> d;
    edge[i].PB({i, c, d});
  }

  vector<VL> mincost = dijkstra(0, n, s, edge);

  FOR(i, 1, n - 1) cout << MIN(mincost[i]) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PQ priority_queue<vector<ll>, vector<vector<ll>>, greater<vector<ll>>>
using ll = long long;
const int INF = 1001001001;
const ll maxS = 3000;

map<int, ll> dij(int f, ll s, ll n, vector<vector<vector<ll>>> &edge) {
  map<int, ll> mintime;
  vector<vector<ll>> mincost(maxS + 5, vector<ll>(n, INF));
  s = min(s, maxS);
  mincost[s][f] = 0;

  PQ pq;
  pq.push({mincost[s][f], s, f});

  while (!pq.empty()) {
    vector<ll> now = pq.top();
    pq.pop();
    if (!mintime.count(now[2]))
      mintime[now[2]] = now[0];
    if ((ll)mintime.size() == n)
      return mintime;

    vector<vector<ll>> &v = edge[now[2]];
    ll l = v.size();

    rep(i, l) {
      ll nextS = min(now[1] + v[i][1], maxS);
      if (nextS < 0)
        continue;

      if (mincost[nextS][v[i][0]] <= now[0] + v[i][2])
        continue;
      mincost[nextS][v[i][0]] = now[0] + v[i][2];
      pq.push({mincost[nextS][v[i][0]], nextS, v[i][0]});
    }
  }
}

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

  vector<vector<vector<ll>>> edge(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    ll a, b;
    cin >> a >> b;
    u--, v--;
    edge[u].push_back({v, -a, b});
    edge[v].push_back({u, -a, b});
  }
  rep(i, n) {
    ll c, d;
    cin >> c >> d;
    edge[i].push_back({i, c, d});
  }

  map<int, ll> mintime = dij(0, s, n, edge);
  for (auto p : mintime) {
    if (p.first == 0)
      continue;
    cout << p.second << endl;
  }
  return 0;
}