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

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<ll, int> Pair;

vector<vector<int>> e;

int N, M, S, K;
int P, Q;
int iszombi[100000];
int danger[100000];
ll d[100000];

void bfs() {
  queue<Pair> q;
  for (int i = 0; i < K; i++)
    q.push(Pair(danger[i], S));
  while (q.size()) {
    auto tmp = q.front();
    q.pop();
    if (tmp.second == 0)
      continue;

    for (int i = 0; i < e[tmp.first].size(); i++) {
      auto next = e[tmp.first][i];
      if (iszombi[next] == 0) {
        iszombi[next] = 1;
        q.push(Pair(next, tmp.second - 1));
      }
    }
  }
}

void djk() {
  for (int i = 0; i < N; i++)
    d[i] = 1145141919810;
  priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
  pq.push(Pair(0, 0));
  d[0] = 0;
  while (pq.size()) {
    auto tmp = pq.top();
    pq.pop();
    if (tmp.first > d[tmp.second])
      continue;

    for (int i = 0; i < e[tmp.second].size(); i++) {
      auto next = e[tmp.second][i];
      ll plus = iszombi[next] == 1 ? Q : P;
      if (iszombi[next] == 2)
        continue;
      if (d[next] > d[tmp.second] + plus) {
        d[next] = d[tmp.second] + plus;
        pq.push(Pair(d[next], next));
      }
    }
  }
}

int main() {
  cin >> N >> M >> K >> S;
  cin >> P >> Q;
  for (int i = 0; i < K; i++) {
    int a;
    cin >> a;
    iszombi[a - 1] = 2;
    danger[i] = a - 1;
  }

  e.resize(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  bfs();

  djk();

  cout << d[N - 1] - (iszombi[N - 1] == 1
                          ? Q
                          : (iszombi[N - 1] == 0 ? P : 1145141919810))
       << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<ll, int> Pair;

vector<vector<int>> e;

int N, M, S, K;
int P, Q;
int iszombi[100000];
int danger[100000];
ll d[100000];

void bfs() {
  queue<Pair> q;
  for (int i = 0; i < K; i++)
    q.push(Pair(danger[i], S));
  while (q.size()) {
    auto tmp = q.front();
    q.pop();
    if (tmp.second == 0)
      continue;

    for (int i = 0; i < e[tmp.first].size(); i++) {
      auto next = e[tmp.first][i];
      if (iszombi[next] != 2) {
        iszombi[next] = 1;
        q.push(Pair(next, tmp.second - 1));
      }
    }
  }
}

void djk() {
  for (int i = 0; i < N; i++)
    d[i] = 1145141919810;
  priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
  pq.push(Pair(0, 0));
  d[0] = 0;
  while (pq.size()) {
    auto tmp = pq.top();
    pq.pop();
    if (tmp.first > d[tmp.second])
      continue;

    for (int i = 0; i < e[tmp.second].size(); i++) {
      auto next = e[tmp.second][i];
      ll plus = iszombi[next] == 1 ? Q : P;
      if (iszombi[next] == 2)
        continue;
      if (d[next] > d[tmp.second] + plus) {
        d[next] = d[tmp.second] + plus;
        pq.push(Pair(d[next], next));
      }
    }
  }
}

int main() {
  cin >> N >> M >> K >> S;
  cin >> P >> Q;
  for (int i = 0; i < K; i++) {
    int a;
    cin >> a;
    iszombi[a - 1] = 2;
    danger[i] = a - 1;
  }

  e.resize(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  bfs();

  djk();

  cout << d[N - 1] - (iszombi[N - 1] == 1
                          ? Q
                          : (iszombi[N - 1] == 0 ? P : 1145141919810))
       << endl;
  return 0;
}