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

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

ll INF = (1e17);
vector<vector<ll>> N;
ll n, m, k, s;
ll q, p;
ll mati[200000];
ll cost[200000];

ll dist[200000];
void dijkstra(int costA, int costB) {
  priority_queue<P, vector<P>, greater<P>> Q;
  for (int i = 1; i <= n; i++)
    if (dist[i] == 0)
      Q.push(P(0, i));
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    ll cost = p.first;
    ll pos = p.second;

    if (dist[pos] < cost)
      continue;
    for (int i = 0; i < (int)N[pos].size(); i++) {
      ll to = N[pos][i];
      ll ncost = cost;

      if (to != n) {
        if (mati[to] == 0)
          ncost += costA;
        if (mati[to] == 1)
          continue;
        if (mati[to] == 2)
          ncost += costB;
      }

      if (dist[to] > ncost) {
        dist[to] = ncost;
        Q.push(P(ncost, to));
      }
    }
  }
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m >> k >> s;
  cin >> p >> q;

  for (int i = 1; i <= n; i++)
    dist[i] = INF;

  ll c;
  while (k--) {
    cin >> c;
    mati[c] = 1;
    dist[c] = 0;
  }

  N.resize(n + 1);
  while (m--) {
    ll a, b;
    cin >> a >> b;
    N[a].push_back(b);
    N[b].push_back(a);
  }

  dijkstra(1, 1);

  for (int i = 1; i <= n; i++) {
    if (dist[i] == 0)
      mati[i] = 1;
    if (1 <= dist[i] && dist[i] <= s)
      mati[i] = 2;
    if (s < dist[i])
      mati[i] = 0;
  }

  for (int i = 1; i <= n; i++)
    dist[i] = INF;
  dist[1] = 0;
  dijkstra(p, q);
  cout << dist[n] << endl;

  /*
  while(!Qb.empty()){
    ll a=Qb.front().first,b=Qb.front().second;
    Qb.pop();
    if(mati[a]==0)mati[a]=2;
    if(a>=s) continue;
    for(ll i=0;i<(ll)N[b].size();i++) {
      if(mati[ N[b][i] ]==2)continue;
      Qb.push(P(a+1,N[b][i]));
      if(mati[ N[b][i] ]==0)mati[ N[b][i] ] = 2;
    }
  }

  for(int i=0;i<=n;i++) cost[i]=1e+9;
  priority_queue<P, vector<P>, greater<P> > Q;
  Q.push(P(0,1));
  while(!Q.empty()){
    cout<<"OK"<<endl;
    ll a=Q.top().first,b=Q.top().second;
    if(b==n) break;
    Q.pop();
    if(cost[b]<a) continue;

    if(b!=1){
      if(mati[b]==2) a+=q;
      else a+=p;
    }

    for(int i=0;i<(int)N[b].size();i++)
      if(mati[N[b][i]]!=1 && cost[b]>a){
        cost[b]=a;
        Q.push(P(a,N[b][i]));
      }
  }
  cout<<Q.top().first<<endl;
  */
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
ll mati[200000];
priority_queue<PP, vector<PP>, greater<PP>> Q;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k, s;
  cin >> n >> m >> k >> s;
  ll q, p;
  cin >> p >> q;
  ll c;
  // memset(mati,0,sizeof(mati));
  queue<P> Qb;
  while (k--) {
    cin >> c;
    mati[c] = 1;
    Qb.push(P(0, c));
  }
  vector<vector<ll>> N(n + 1);
  while (m--) {
    ll a, b;
    cin >> a >> b;
    N[a].push_back(b);
    N[b].push_back(a);
  }
  while (!Qb.empty()) {
    ll a = Qb.front().first, b = Qb.front().second;
    Qb.pop();
    if (a > s)
      continue;
    if (mati[b] != 1)
      mati[b] = 2;
    for (ll i = 0; i < (ll)N[b].size(); i++)
      Qb.push(P(a + 1, N[b][i]));
  }

  for (ll i = 0; i < (ll)N[1].size(); i++)
    Q.push(PP(0, P(N[1][i], 0)));
  while (1) {
    if (Q.empty())
      continue;
    ll a = Q.top().first, b = Q.top().second.first, c = Q.top().second.second;
    if (b == n)
      break;
    Q.pop();
    if (mati[b] == 2)
      a += q;
    else
      a += p;
    for (ll i = 0; i < (ll)N[b].size(); i++)
      if (mati[N[b][i]] != 1 && N[b][i] != c)
        Q.push(PP(a, P(N[b][i], b)));
  }
  cout << Q.top().first << endl;

  return 0;
}