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

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

using LL = long long;
struct Vertex {
  int id;
  LL coin, time;
};
struct Edge {
  int from, to;
  LL coin, time;
};
using Graph = vector<vector<Edge>>;

int main() {
  int N, M;
  LL S;
  cin >> N >> M >> S;
  Graph G(N);
  for (auto i = 0; i < M; ++i) {
    int U, V;
    LL A, B;
    cin >> U >> V >> A >> B;
    --U;
    --V;
    G[U].push_back({U, V, A, B});
    G[V].push_back({V, U, A, B});
  }
  vector<Vertex> V(N);
  for (auto i = 0; i < N; ++i)
    V[i].id = i;
  for (auto &v : V)
    cin >> v.coin >> v.time;

  vector<LL> d(N, -1);

  priority_queue<Vertex, vector<Vertex>, function<bool(Vertex &, Vertex &)>> q(
      [](auto &l, auto &r) {
        if (l.time != r.time)
          return l.time > r.time;
        if (l.coin != r.coin)
          return l.coin < r.coin;
        return l.id < r.id;
      });
  vector<vector<LL>> memo(N, vector<LL>(2500 + 1, -1));

  q.push({0, min<LL>(S, 2500), 0});
  while (!q.empty()) {
    auto cur = q.top();
    q.pop();

    if (memo[cur.id][cur.coin] != -1)
      continue;
    memo[cur.id][cur.coin] = cur.time;
    if (d[cur.id] == -1)
      d[cur.id] = cur.time;

    for (auto &e : G[cur.id]) {
      auto &v = V[cur.id];
      for (auto nex :
           {Vertex{e.to, cur.coin - e.coin, cur.time + e.time},
            Vertex{v.id, min<LL>(cur.coin + v.coin, 2500), cur.time + v.time}})
        if (0 <= nex.coin)
          if (memo[nex.id][nex.coin] == -1)
            q.push({nex.id, nex.coin, nex.time});
    }
  }

  for (auto i = 1; i < N; ++i)
    cout << d[i] << endl;
}


Error: 0

Fixed submission:

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

using LL = long long;
struct Vertex {
  int id;
  LL coin, time;
};
struct Edge {
  int from, to;
  LL coin, time;
};
using Graph = vector<vector<Edge>>;

int main() {
  int N, M;
  LL S;
  cin >> N >> M >> S;
  Graph G(N);
  for (auto i = 0; i < M; ++i) {
    int U, V;
    LL A, B;
    cin >> U >> V >> A >> B;
    --U;
    --V;
    G[U].push_back({U, V, A, B});
    G[V].push_back({V, U, A, B});
  }
  vector<Vertex> V(N);
  for (auto i = 0; i < N; ++i)
    V[i].id = i;
  for (auto &v : V)
    cin >> v.coin >> v.time;

  vector<LL> d(N, -1);

  priority_queue<Vertex, vector<Vertex>, function<bool(Vertex &, Vertex &)>> q(
      [](auto &l, auto &r) {
        if (l.time != r.time)
          return l.time > r.time;
        if (l.coin != r.coin)
          return l.coin < r.coin;
        return l.id < r.id;
      });
  vector<vector<LL>> memo(N, vector<LL>(2500 + 1, -1));

  q.push({0, S, 0});
  while (!q.empty()) {
    auto cur = q.top();
    q.pop();

    if (memo[cur.id][cur.coin] != -1)
      continue;
    memo[cur.id][cur.coin] = cur.time;
    if (d[cur.id] == -1)
      d[cur.id] = cur.time;

    for (auto &e : G[cur.id]) {
      auto &v = V[cur.id];
      for (auto nex :
           {Vertex{e.to, cur.coin - e.coin, cur.time + e.time},
            Vertex{v.id, min<LL>(cur.coin + v.coin, 2500), cur.time + v.time}})
        if (0 <= nex.coin)
          if (memo[nex.id][nex.coin] == -1)
            q.push({nex.id, nex.coin, nex.time});
    }
  }

  for (auto i = 1; i < N; ++i)
    cout << d[i] << endl;
}