Problem p00546 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;
struct edge {
  ll to;
  ll cost;
};
ll N, M, K, S;
ll Pa, Q, C[100000], A[200000], B[200000];
bool zon[100000];
bool terr[100000];
queue<ll> q[2];
vector<edge> G[100000];
ll b = 0;
ll d[100000];
vector<ll> hen[100000];
const ll INF = 0xffffffffff;
int main() {
  scanf("%lld%lld%lld%lld%lld%lld", &N, &M, &K, &S, &Pa, &Q);
  for (ll i = 0; i < K; i++) {
    scanf("%lld", &C[i]);
    C[i]--;
    zon[C[i]] = 1;
    terr[C[i]] = 1;
    q[b].push(C[i]);
  }
  for (ll i = 0; i < M; i++) {
    scanf("%lld%lld", &A[i], &B[i]);
    A[i]--;
    B[i]--;
    hen[A[i]].push_back(B[i]);
    hen[B[i]].push_back(A[i]);
  }
  for (ll i = 0; i < S; i++) {
    while (q[b].size()) {
      ll now = q[b].front();
      q[b].pop();
      for (ll j = 0; j < hen[now].size(); j++) {
        if (!terr[hen[now][j]]) {
          terr[hen[now][j]] = 1;
          q[!b].push(hen[now][j]);
        }
      }
    }
    b = !b;
  }
  for (ll i = 0; i < M; i++) {
    if (!zon[A[i]] && !zon[B[i]]) {
      if (terr[B[i]]) {
        G[A[i]].push_back((edge){B[i], Q});
      } else {
        G[A[i]].push_back((edge){B[i], Pa});
      }
      if (terr[A[i]]) {
        G[B[i]].push_back((edge){A[i], Q});
      } else {
        G[B[i]].push_back((edge){A[i], Pa});
      }
    }
  }
  fill(d, d + N, INF);
  d[0] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll x = p.second;
    if (d[x] < p.first)
      continue;
    for (ll i = 0; i < G[x].size(); i++) {
      edge e = G[x][i];
      if (d[e.to] > d[x] + e.cost) {
        d[e.to] = d[x] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  if (terr[N - 1])
    d[N - 1] -= Q;
  else
    d[N - 1] -= Pa;
  printf("%lld\\n", d[N - 1]);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;
struct edge {
  ll to;
  ll cost;
};
ll N, M, K, S;
ll Pa, Q, C[100000], A[200000], B[200000];
bool zon[100000];
bool terr[100000];
queue<ll> q[2];
vector<edge> G[100000];
ll b = 0;
ll d[100000];
vector<ll> hen[100000];
const ll INF = 0xffffffffff;
int main() {
  scanf("%lld%lld%lld%lld%lld%lld", &N, &M, &K, &S, &Pa, &Q);
  for (ll i = 0; i < K; i++) {
    scanf("%lld", &C[i]);
    C[i]--;
    zon[C[i]] = 1;
    terr[C[i]] = 1;
    q[b].push(C[i]);
  }
  for (ll i = 0; i < M; i++) {
    scanf("%lld%lld", &A[i], &B[i]);
    A[i]--;
    B[i]--;
    hen[A[i]].push_back(B[i]);
    hen[B[i]].push_back(A[i]);
  }
  for (ll i = 0; i < S; i++) {
    while (q[b].size()) {
      ll now = q[b].front();
      q[b].pop();
      for (ll j = 0; j < hen[now].size(); j++) {
        if (!terr[hen[now][j]]) {
          terr[hen[now][j]] = 1;
          q[!b].push(hen[now][j]);
        }
      }
    }
    b = !b;
  }
  for (ll i = 0; i < M; i++) {
    if (!zon[A[i]] && !zon[B[i]]) {
      if (terr[B[i]]) {
        G[A[i]].push_back((edge){B[i], Q});
      } else {
        G[A[i]].push_back((edge){B[i], Pa});
      }
      if (terr[A[i]]) {
        G[B[i]].push_back((edge){A[i], Q});
      } else {
        G[B[i]].push_back((edge){A[i], Pa});
      }
    }
  }
  fill(d, d + N, INF);
  d[0] = 0;
  priority_queue<P> que;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll x = p.second;
    if (d[x] < p.first)
      continue;
    for (ll i = 0; i < G[x].size(); i++) {
      edge e = G[x][i];
      if (d[e.to] > d[x] + e.cost) {
        d[e.to] = d[x] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
  if (terr[N - 1])
    d[N - 1] -= Q;
  else
    d[N - 1] -= Pa;
  printf("%lld\\n", d[N - 1]);
}