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

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#define INF 1e7
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
struct edge {
  LL to, cost;
};

vector<int> danger;
vector<int> v[114514];
LL ddis[114514];
vector<edge> G[114514];
LL dis[114514];

void dijkstra(int st) {
  priority_queue<P, vector<P>, greater<P>> Q;
  fill(dis, dis + 110000, 1e17);
  dis[st] = 0;
  Q.push(P(0, st));

  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int V = p.second;
    if (dis[V] < p.first)
      continue;
    for (int i = 0; i < G[V].size(); i++) {
      edge e = G[V][i];
      if (dis[e.to] > dis[V] + e.cost) {
        dis[e.to] = dis[V] + e.cost;
        Q.push(P(dis[e.to], e.to));
      }
    }
  }
}

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

  int p, q;
  cin >> p >> q;

  for (int i = 0; i < k; i++) {
    int a;
    cin >> a;
    danger.push_back(a - 1);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < danger.size(); i++) {
    v[114500].push_back(danger[i]);
  }

  queue<int> qe;
  queue<int> nq;
  fill(ddis, ddis + 114501, INF);
  ddis[114500] = 0;

  qe.push(114500);

  for (int x = -1; x < s; x++) {
    int z = qe.size();
    for (int i = 0; i < z; i++) {
      int a = qe.front();
      qe.pop();
      for (int j = 0; j < v[a].size(); j++) {
        if (ddis[v[a][j]] == 10000000) {
          ddis[v[a][j]] = x;
          nq.push(v[a][j]);
        }
      }
    }
    while (nq.size()) {
      qe.push(nq.front());
      nq.pop();
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < v[i].size(); j++) {

      bool ba = false, bb = false;
      for (int k = 0; k < danger.size(); k++) {
        if (danger[k] == i)
          ba = true;
        else if (danger[k] == v[i][j])
          bb = true;
      }

      if (ba || bb)
        continue;

      if (v[i][j] != n - 1) {
        if ((ddis[i] == 10000000) && (ddis[v[i][j]] == 10000000)) {
          G[i].push_back({v[i][j], p});
        } else if (ddis[v[i][j]] == 10000000) {
          G[i].push_back({v[i][j], p});
        } else {
          G[i].push_back({v[i][j], q});
        }
      } else {
        G[i].push_back({v[i][j], 0});
      }
    }
  }

  dijkstra(0);
  cout << dis[n - 1] << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#define INF 1e9
#define LINF 1e17
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
struct edge {
  LL to, cost;
};

vector<int> danger;
vector<int> v[114514];
LL ddis[114514];

vector<edge> G[114514];
LL dis[114514];

void dijkstra(int st) {
  priority_queue<P, vector<P>, greater<P>> Q;
  fill(dis, dis + 110000, LINF);
  dis[st] = 0;
  Q.push(P(0, st));

  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int V = p.second;
    if (dis[V] < p.first)
      continue;
    for (int i = 0; i < G[V].size(); i++) {
      edge e = G[V][i];
      if (dis[e.to] > dis[V] + e.cost) {
        dis[e.to] = dis[V] + e.cost;
        Q.push(P(dis[e.to], e.to));
      }
    }
  }
}

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

  int p, q;
  cin >> p >> q;

  for (int i = 0; i < k; i++) {
    int a;
    cin >> a;
    danger.push_back(a - 1);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < danger.size(); i++) {
    v[114500].push_back(danger[i]);
  }

  queue<int> qe;
  queue<int> nq;
  fill(ddis, ddis + 114520, INF);
  ddis[114500] = 0;

  qe.push(114500);

  for (int x = -1; x < s; x++) {

    int z = qe.size();
    for (int i = 0; i < z; i++) {
      int a = qe.front();
      qe.pop();
      for (int j = 0; j < v[a].size(); j++) {
        if (ddis[v[a][j]] == INF) {
          ddis[v[a][j]] = x;
          nq.push(v[a][j]);
        }
      }
    }
    while (nq.size()) {
      qe.push(nq.front());
      nq.pop();
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < v[i].size(); j++) {

      bool ba = false, bb = false;
      for (int k = 0; k < danger.size(); k++) {
        if (danger[k] == i)
          ba = true;
        else if (danger[k] == v[i][j])
          bb = true;
      }

      if (ba || bb)
        continue;

      if (ddis[i] == INF && ddis[v[i][j]] == INF) {
        G[i].push_back({v[i][j], p});
      } else if (ddis[v[i][j]] == INF) {
        G[i].push_back({v[i][j], p});
      } else {
        G[i].push_back({v[i][j], q});
      }
    }
  }

  dijkstra(0);
  cout << dis[n - 1] << endl;

  getchar();
  getchar();
  return 0;
}