Problem:
ゾンビ島 (Zombie Island)
問題
JOI 君が住んでいる島がゾンビに侵略されてしまった．JOI 君は島で一番安全な避難場所として設定されているシェルターに逃げ込むことにした．
JOI 君が住んでいる島は町 1 から町 N までの N 個の町からなり，町と町とは道路で結ばれている．島には M 本の道路があり，すべての道路は異なる 2 つの町を結んでいる．JOI 君は道路を双方向に自由に移動できるが，道路以外を通って町から別の町に行くことはできない．
いくつかの町はゾンビに支配されており，訪れることが出来ない．ゾンビに支配されている町から S 本以下の道路を使って到達できる町を
危険な町
という．それ以外の町を
危険でない町
という．
JOI 君の家は町 1 にあり，避難先のシェルターは町 N にある．町 1，町 N はゾンビに支配されていない．島の道路は移動するのに時間がかかるので，JOI 君は町を移動するたびに，移動先の町で一晩宿泊しなければならない．JOI 君は，危険でない町で宿泊する場合は宿泊費が P 円の安い宿に泊まるが，危険な町で宿泊する場合はセキュリティのサービスが優良な宿泊費が Q 円の高級宿に泊まる．JOI 君はできるだけ宿泊費が安くなるように移動して，町 N まで避難したい．町 1 や町 N では宿泊する必要はない．
JOI 君が 町 1 から町 N まで移動するときに必要な宿泊費の合計の最小値を求めよ．
入力
入力は 2 + K + M 行からなる．
1 行目には，4 つの整数 N, M, K,  S (2 ≦ N ≦ 100000, 1 ≦ M ≦ 200000, 0 ≦ K ≦ N - 2, 0 ≦ S ≦ 100000) が空白を区切りとして書かれている．これは，島が N 個の町と M 本の道路からなり，N 個の町のうち K 個の町がゾンビに支配されており，ゾンビに支配されている町から S 本以下の道路を使って到達できる町を危険な町と呼ぶことを表す．
2 行目には，2 つの整数 P, Q (1 ≦ P ＜ Q ≦ 100000) が空白を区切りとして書かれている．これは，JOI 君が危険でない町では宿泊費が P 円の宿に泊まり，危険な町では宿泊費が Q 円の宿に泊まることを表す．
続く K 行のうちの i 行目 (1 ≦ i ≦ K) には，整数 C
i
(2 ≦ C
i
≦ N - 1) が書かれている．これは，町 C
i
がゾンビに支配されていることを表す．C
1
, ..., C
K
は全て異なる．
続く M 行のうちの j 行目 (1 ≦ j ≦ M) には，2 つの整数 A
j
, B
j
(1 ≦ A
j
＜ B
j
≦ N) が空白を区切りとして書かれている．これは，町 A
j
と町 B
j
との間に道路が存在することを表す．同じ (A
j
, B
j
) の組が 2 回以上書かれていることはない．
与えられる入力データにおいては，町 1 から町 N までゾンビに支配されていない町のみを通って移動できることが保証されている．
出力
JOI 君が町 1 から町 N まで移動するときに必要な宿泊費の合計の最小値を 1 行で出力せよ．
出力が 32 ビット符号付き整数の範囲に収まるとは限らないことに注意せよ．
入出力例
入力例 1
13 21 1 1
1000 6000
7
1 2
3 7
2 4
5 8
8 9
2 5
3 4
4 7
9 10
10 11
5 9
7 12
3 6
4 5
1 3
11 12
6 7
8 11
6 13
7 8
12 13
出力例 1
11000
入力例 2
21 26 2 2
1000 2000
5
16
1 2
1 3
1 10
2 5
3 4
4 6
5 8
6 7
7 9
8 10
9 10
9 11
11 13
12 13
12 15
13 14
13 16
14 17
15 16
15 18
16 17
16 19
17 20
18 19
19 20
19 21
出力例 2
15000
入出力例 1 は，以下の図に対応している．円は町を，線は道路を表す．
この場合，町 3，町 4，町 6，町 8，町 12 が危険な町である．
以下のような順番で町を移動すると，宿泊費の合計を最小にできる．
町 1 から町 2 に行く．町 2 で宿泊費が 1000 円の安い宿に宿泊する．
町 2 から町 5 に行く．町 5 で宿泊費が 1000 円の安い宿に宿泊する．
町 5 から町 9 に行く．町 9 で宿泊費が 1000 円の安い宿に宿泊する．
町 9 から町 10 に行く．町 10 で宿泊費が 1000 円の安い宿に宿泊する．
町 10 から町 11 に行く．町 11 で宿泊費が 1000 円の安い宿に宿泊する．
町 11 から町 12 に行く．町 12 で宿泊費が 6000 円の高級宿に宿泊する．
町 12 から町 13 に行く．町 13 では宿泊しない．
JOI 君がこのような経路で移動したとき，宿泊費の合計は 11000 円になるので，11000 を出力する．
情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』

Submitted solutions:

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

using ll = long long;
using pll = pair<ll, ll>;

constexpr ll INF = 1e18;

int main() {
    int N, M, K, S;
    ll P, Q;
    cin >> N >> M >> K >> S;
    cin >> P >> Q;

    vector<ll> zd(N, INF);
    queue<int> que1;
    for(int i=0; i<K; ++i) {
        int c;
        cin >> c;
        c--;
        que1.push(c);
        zd[c] = 0;
    }

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

    while(!que1.empty()) {
        int v = que1.front();
        que1.pop();
        for(auto to : g[v]) {
            if(zd[to] == INF) {
                zd[to] = zd[v] + 1;
                que1.push(to);
            }
        }
    }

    vector<ll> d(N, INF);
    d[0] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> que;
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        pll p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto to : g[v]) {
            if(zd[to] == 0) {
                continue;
            }
            ll cost = to == N-1 ? 0 : (zd[to] > S ? P : Q);
            if(d[to] > d[v] + cost) {
                d[to] = d[v] + cost;
                que.push(make_pair(d[to], to));
            }
        }
    }
    cout << d[N-1] << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 10988
final_rank: 6

code_snippet: #define _GLGBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll N, M, K, S, P, Q, answer = 0;
ll dist[100009], zombie_dist[100009];
set<ll> G[100009];

int main() {
    cin >> N >> M >> K >> S;
    cin >> P >> Q;

    queue<ll> Queue;

    for (ll i = 1; i <= N; i++) 
        dist[i] = -1LL, zombie_dist[i] = -1LL;

    for (ll j = 0; j < K; j++) {
        ll C;
        cin >> C;

        Queue.push(C);
        zombie_dist[C] = 0LL;
    }

    for (ll l = 0; l < M; l++) {
        ll A, B;
        cin >> A >> B;

        G[A].insert(B);
        G[B].insert(A);
    }

    while (!Queue.empty()) {
        ll pos = Queue.front();
        Queue.pop();
        for (ll nex : G[pos]) {
            if (
                zombie_dist[nex] == -1LL ||
                zombie_dist[nex] > zombie_dist[pos] + 1LL
            ) {
                zombie_dist[nex] = zombie_dist[pos] + 1LL;
                if (zombie_dist[nex] < S)
                    Queue.push(nex);
            }
        }
    }

    Queue.push(1LL); dist[1LL] = 0LL;

    while (!Queue.empty()) {
        ll pos = Queue.front();
        Queue.pop();
        for (ll nex : G[pos]) {
            if (
                zombie_dist[nex] != 0 && (
                    dist[nex] == -1LL ||
                    (
                        zombie_dist[nex] == -1LL &&
                        dist[nex] > dist[pos] + P
                    ) || (
                        zombie_dist[nex] != -1LL &&
                        dist[nex] > dist[pos] + Q
                    )
                )
            ) {
                if (zombie_dist[nex] == -1LL)
                    dist[nex] = dist[pos] + P;
                else
                    dist[nex] = dist[pos] + Q;
                
                Queue.push(nex);
            }
        }
    }

    if (zombie_dist[N] == -1)
        cout << dist[N] - P << '\n';
    else
        cout << dist[N] - Q << '\n';

    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 28524
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll=vector<ll>;
using vvll=vector<vll>;


int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N,M,K,S,P,Q;
    cin>>N>>M>>K>>S>>P>>Q;
    vector<ll> dist(N,1e18);
    queue<ll> que;
    for(int i=0;i<K;i++){
        ll c;
        cin>>c;
        c--;
        dist[c]=0;
        que.push(c);
    }
    vector<vll> G(N);
    for(int i=0;i<M;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<bool> seen(N,false);
    while(!que.empty()){
        int p=que.front();
        que.pop();
        if(seen[p])continue;
        seen[p]=1;
        for(int v:G[p]){
            if(dist[v]<=dist[p]+1)continue;
            if(seen[v])continue;
            dist[v]=dist[p]+1;
            que.push(v);
        }
    }

    seen.assign(N,false);
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que2;
    que2.push({0,0});
    vll D(N,1e18);
    D[0]=0;
    while(!que2.empty()){
        auto [c,p]=que2.top();
        que2.pop();
        if(seen[p])continue;
        seen[p]=1;
        for(int v:G[p]){
            if(dist[v]==0)continue;
            ll nc=c+(dist[v]<=S?Q:P);
            if(D[v]<=nc)continue;
            if(seen[v])continue;
            D[v]=nc;
            que2.push({D[v],v});
        }
    }
    cout<<D[N-1]-(dist[N-1]<=S?Q:P)<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 13496
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k, s;
    cin >> n >> m >> k >> s;
    ll p, q;
    cin >> p >> q;
    vector<bool> dead(n);
    for (int i = 0; i < k; ++i) {
        int c;
        cin >> c;
        dead[c - 1] = true;
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        x -= 1, y -= 1;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<int> d(n, -1);
    queue<int> que;
    for (int i = 0; i < n; ++i) {
        if (dead[i]) {
            d[i] = 0;
            que.push(i);
        }
    }
    while (que.size()) {
        int ss = que.front();
        que.pop();
        for (int tt : g[ss]) {
            if (d[tt] == -1) {
                d[tt] = d[ss] + 1;
                que.push(tt);
            }
        }
    }
    vector<ll> dp(n, 1e18);
    dp[0] = 0;
    using P = pair<ll, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, 0});
    while (pq.size()) {
        auto uo = pq.top();
        pq.pop();
        int cur = uo.second;
        ll cost = uo.first;
        if (dp[cur] != cost) continue;
        for (int nxt : g[cur]) {
            if (dead[nxt]) continue;
            ll cc = (d[nxt] <= s ? q : p);
            if (nxt == n - 1) cc = 0;
            if (dp[nxt] > cost + cc) {
                dp[nxt] = cost + cc;
                pq.push({dp[nxt], nxt});
            }
        }
    }
    cout << dp.back() << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 10920
final_rank: 4

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){ return graph.size(); }
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto N=in(),M=in(),K=in(),S=in();
	auto P=in(),Q=in();
	auto C=vecin(K);
	sort(ALL(C));

	vector<pair<ll,ll>> L(M);
	ConnectNodeInfo connect(N);
	REP(i,M){
		auto u=in()-1,v=in()-1;
		L[i]={min(u,v),max(u,v)};
		connect.AddNonDirectionalConnection(u,v,1);
	}
	vll dist(N,1ll<<60);
	queue<ll> DQ;
	for(auto& x:C){
		DQ.push(x-1);
		dist[x-1]=0;
	}

	while(!DQ.empty()){
		auto vertex=DQ.front();
		DQ.pop();
		for(auto& [node,weight]:connect[vertex]){
			if(dist[vertex]+1<dist[node]){
				dist[node] = dist[vertex]+1;
				DQ.push(node);
			}
		}
	}

	ConnectNodeInfo connect2(N);
	REP(i,M){
		auto [u,v]=L[i];
		if(binary_search(ALL(C),u+1) || binary_search(ALL(C),v+1)) continue;
		if(v==N-1){
			connect2.AddDirectionalConnection(u,v,0);
		}
		else{
			if(dist[v]<=S) connect2.AddDirectionalConnection(u,v,Q);
			else connect2.AddDirectionalConnection(u,v,P);
		}
		if(dist[u]<=S) connect2.AddDirectionalConnection(v,u,Q);
		else connect2.AddDirectionalConnection(v,u,P);
	}

	Dijkstra dij;
	dij.CalcShortestPath(0,connect2);
	out(dij.GetDistance(N-1));

	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 33328
final_rank: 14

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){ return graph.size(); }
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto N=in(),M=in(),K=in(),S=in();
	auto P=in(),Q=in();
	auto C=vecin(K);

	vector<pair<ll,ll>> L(M);
	ConnectNodeInfo connect(N);
	REP(i,M){
		auto u=in()-1,v=in()-1;
		L[i]={min(u,v),max(u,v)};
		connect.AddNonDirectionalConnection(u,v,1);
	}
	vll dist(N,1ll<<60);
	queue<ll> DQ;
	for(auto& x:C){
		DQ.push(x-1);
		dist[x-1]=0;
	}

	while(!DQ.empty()){
		auto vertex=DQ.front();
		DQ.pop();
		for(auto& [node,weight]:connect[vertex]){
			if(dist[vertex]+1<dist[node]){
				dist[node] = dist[vertex]+1;
				DQ.push(node);
			}
		}
	}

	ConnectNodeInfo connect2(N);
	REP(i,M){
		auto [u,v]=L[i];
		if(binary_search(ALL(C),u+1) || binary_search(ALL(C),v+1)) continue;
		if(v==N-1){
			connect2.AddDirectionalConnection(u,v,0);
		}
		else{
			if(dist[v]<=S) connect2.AddDirectionalConnection(u,v,Q);
			else connect2.AddDirectionalConnection(u,v,P);
		}
		if(dist[u]<=S) connect2.AddDirectionalConnection(v,u,Q);
		else connect2.AddDirectionalConnection(v,u,P);
	}

	Dijkstra dij;
	dij.CalcShortestPath(0,connect2);
	out(dij.GetDistance(N-1));

	return 0;
}
accuracy: 0.6
time_ms: 70
memory_kb: 33276
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define coutf(f) cout << fixed << setprecision(f)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)

using Graph1 = vector<vector<int>>;

const ll INF = 1LL << 60;

struct Edge {
   int to;
   ll w;
   Edge(int to, ll w) : to(to), w(w) {}
};

using Graph2 = vector<vector<Edge>>;

template<class T> bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   else return false;
}

int main() {
   int n, m, k, s;
   cin >> n >> m >> k >> s;
   int p, q;
   cin >> p >> q;
   vector<int> c(k);
   Graph1 G1(n);
   rep (i,k) {
      cin >> c[i];
      c[i]--;
   }
   sort(all(c));
   vector<int> a(m), b(m);
   rep (i,m) {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
      G1[a[i]].pb(b[i]);
      G1[b[i]].pb(a[i]);
   }
   vector<int> dist1(n, -1);
   queue<int> que1;
   rep (i,k) {
      dist1[c[i]] = 0;
      que1.push(c[i]);
   }
   while (!que1.empty()) {
      int v = que1.front();
      que1.pop();
      for (int nv : G1[v]) {
         if (dist1[nv] != -1) continue;
         dist1[nv] = dist1[v]+1;
         que1.push(nv);
      }
   }
   vector<bool> ok(n);
   rep (i,n) {
      if (dist1[i] <= s) ok[i] = false;
      else ok[i] = true;
   }
   Graph2 G2(n);
   rep (i,m) {
      if (binary_search(all(c), a[i])) continue;
      if (binary_search(all(c), b[i])) continue;
      if (ok[b[i]]) {
         G2[a[i]].pb(Edge(b[i],p));
      } else {
         G2[a[i]].pb(Edge(b[i],q));
      }
      if (ok[a[i]]) {
         G2[b[i]].pb(Edge(a[i],p));
      } else {
         G2[b[i]].pb(Edge(a[i],q));
      }
   }
   vector<ll> dist2(n, INF);
   dist2[0] = 0;
   priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que2;
   que2.push({dist2[0],0});
   while (!que2.empty()) {
      int v = que2.top().second;
      ll d = que2.top().first;
      que2.pop();
      if (d > dist2[v]) continue;
      for (auto e : G2[v]) {
         if (chmin(dist2[e.to], dist2[v]+e.w)) {
            que2.push({dist2[e.to], e.to});
         }
      }
   }
   ll ans = INF;
   for (auto v : G2[n-1]) {
      ans = min(ans, dist2[v.to]);
   }
   cout << ans << endl;
   return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 25516
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;

const i32 supi = 1e9;
const i64 supl = 1e18;

int main() {
    i32 n, m, k, s; cin >> n >> m >> k >> s;
    i32 p, q; cin >> p >> q;
    vector cs(k, 0);
    for (auto& c : cs) {
        cin >> c;
        c--;
    }
    vector es(m, pair(0, 0));
    for (auto& [a, b] : es) {
        cin >> a >> b;
        a--;
        b--;
    }
    vector G = [&]() -> vector<vector<pair<i32, i32>>> {
        vector ts(n + 1, vector(0, 0));
        for (auto c : cs) {
            ts[n].push_back(c);
        }
        for (auto [a, b] : es) {
            ts[a].push_back(b);
            ts[b].push_back(a);
        }
        vector ds(n + 1, supi);
        ds[n] = 0;
        queue<i32> que({ n });
        while (que.size()) {
            i32 v = que.front();
            que.pop();
            for (auto x : ts[v]) {
                if (ds[x] > ds[v] + 1) {
                    ds[x] = ds[v] + 1;
                    que.push(x);
                }
            }
        }
        vector res(2 * n, vector(0, pair(0, 0)));
        set<i32> ng(cs.begin(), cs.end());
        for (auto [a, b] : es) {
            if (ng.count(a) or ng.count(b)) {
                continue;
            }
            res[a + n].emplace_back(b, 0);
            res[b + n].emplace_back(a, 0);
        }
        for (i32 i = 0 ; i < n ; i++) {
            if (i == 0 or i == n - 1) {
                res[i].emplace_back(i + n, 0);
            }
            else if (ds[i] <= s + 1) {
                res[i].emplace_back(i + n, q);
            }
            else {
                res[i].emplace_back(i + n, p);
            }
        }
        return res;
    }();
    vector ds(2 * n, supl);
    ds[0] = 0;
    priority_queue<pair<i64, i32>, vector<pair<i64, i32>>, greater<pair<i64, i32>>> que;
    que.emplace(0LL, 0);
    while (que.size()) {
        auto [d, v] = que.top();
        que.pop();
        if (d > ds[v]) {
            continue;
        }
        for (auto [x, w] : G[v]) {
            if (ds[x] > d + w) {
                ds[x] = d + w;
                que.emplace(d + w, x);
            }
        }
    }
    // for (auto d : ds) cout << d << ' ';
    // cout << endl;
    cout << ds.back() << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 24392
final_rank: 10

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0623.cc: ゾンビ島 (Zombie Island)
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int INF = 1 << 30;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<ll,int> pli;

/* global variables */

int cs[MAX_N], zds[MAX_N];
vi nbrs[MAX_N];
ll ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, k, s, p, q;
  scanf("%d%d%d%d%d%d", &n, &m, &k, &s, &p, &q);
  
  for (int i = 0; i < k; i++) scanf("%d", cs + i), cs[i]--;

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  fill(zds, zds + n, INF);
  qi qq;
  for (int i = 0; i < k; i++)
    zds[cs[i]] = 0, qq.push(cs[i]);

  while (! qq.empty()) {
    int u = qq.front(); qq.pop();
    for (auto v: nbrs[u])
      if (zds[v] > zds[u] + 1) {
	zds[v] = zds[u] + 1;
	qq.push(v);
      }
  }
  //for (int i = 0; i < n; i++) printf("%d ", zds[i]); putchar('\n');

  fill(ds, ds + n, LINF);
  ds[0] = 0;

  priority_queue<pli> pq;
  pq.push(pli(0, 0));

  while (! pq.empty()) {
    pli ue = pq.top(); pq.pop();
    ll ud = -ue.first;
    int u = ue.second;
    if (ds[u] != ud) continue;
    if (u == n - 1) break;

    for (auto v: nbrs[u])
      if (zds[v] != 0) {
	ll vd = ud + (v != n - 1 ? (zds[v] > s ? p : q) : 0);
	if (ds[v] > vd) {
	  ds[v] = vd;
	  pq.push(pli(-vd, v));
	}
      }
  }

  printf("%lld\n", ds[n - 1]);

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10576
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;
struct edge{
	int to,cost;
};
vector<int>G[100000];
vector<edge>G2[100000];
ll dist[100000];
bool dg[100000],dg2[100000];
int main(){
	int n,m,k,s,p,q,c,a,b;
	cin>>n>>m>>k>>s>>p>>q;
	for(int i=0;i<k;i++){
		cin>>c;
		c--;
		dg[c]=1;
	}
	while(cin>>a>>b){
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	queue<int>que;
	fill(dist,dist+n,1e9);
	for(int i=0;i<n;i++){
		if(dg[i]){
			dist[i]=0;
			que.push(i);
		}
	}
	while(que.size()){
		int v=que.front();
		que.pop();
		for(auto x:G[v]){
			if(dist[x]==1e9){
				dist[x]=dist[v]+1;
				que.push(x);
			}
		}
	}
	for(int i=0;i<n;i++)
		if(dist[i]<=s)
			dg2[i]=1;
	for(int i=0;i<n;i++){
		for(auto x:G[i]){
			if(dg[x])
				continue;
			G2[i].push_back({x,p});
			if(dg2[x])
				G2[i].back().cost=q;
			if(x==n-1)
				G2[i].back().cost=0;
		}
	}
	priority_queue<P,vector<P>,greater<>>pque;
	fill(dist,dist+n,1e18);
	dist[0]=0;
	pque.push({0,0});
	while(pque.size()){
		auto[d,v]=pque.top();
		pque.pop();
		if(dist[v]<d)
			continue;
		for(auto[x,c]:G2[v]){
			if(dist[x]>d+c){
				dist[x]=d+c;
				pque.push({d+c,x});
			}
		}
	}
	cout<<dist[n-1]<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 18340
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define LINF 1000000000000000000
using namespace std;
using ll=long long;
using PL=pair<ll,int>;

int N,M,K,S,P,Q;
vector<int> C;
vector<vector<int>> g;
vector<int> z;

template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

void bfs() {
   queue<int> q;
   vector<int> dist(N,INF);
   for(auto i:C) {
      dist[i]=0;
      z[i]=2;
      q.push(i);
   }
   while(!q.empty()) {
      int u=q.front(); q.pop();
      if(dist[u]+1<=S) for(auto v:g[u]) {
         if(chmin(dist[v],dist[u]+1)) q.push(v);
      }
   }
   rep(i,N) if(dist[i]<=S && z[i]!=2) z[i]=1;
}

ll dijkstra() {
   priority_queue<PL,vector<PL>,greater<PL>> q;
   vector<ll> dist(N,LINF);
   dist[0]=0;
   q.push(make_pair(0,0));
   while(!q.empty()) {
      ll d; int u;
      tie(d,u)=q.top(); q.pop();
      if(d>dist[u]) continue;
      for(auto v:g[u]) {
         if(z[v]==2) continue;
         int c=(z[v] ? Q : P);
         if(v==N-1) c=0;
         if(chmin(dist[v],dist[u]+c)) q.push(make_pair(dist[v],v));
      }
   }
   return dist[N-1];
}

int main(void) {
   cin.tie(0);
   ios::sync_with_stdio(0);
   cin >> N >> M >> K >> S >> P >> Q;
   C.resize(K);
   g.resize(N);
   z.resize(N,0);
   rep(i,K) {
      cin >> C[i];
      C[i]--;
   }
   rep(i,M) {
      int a,b; cin >> a >> b;
      a--; b--;
      g[a].push_back(b);
      g[b].push_back(a);
   }
   bfs();
   cout << dijkstra() << endl;
   return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10592
final_rank: 2

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,K,S,X,Y;
const ll INF=1e18;
vector<P> G[100010];
vector<ll> g[100010];
ll d[100010],c[100010],e[2][200010];

void bfs(){

	vector<ll> v(N+1,INF);
	queue<ll> q;
	for(ll i=1;i<=N;i++) if(c[i]==1){
		v[i]=0;
		q.push(i);
	}

	while(!q.empty()){

		ll a=q.front();
		q.pop();
		for(ll i=0;i<(ll)g[a].size();i++){
			ll b=g[a][i];
			if(v[b]==INF){
				v[b]=v[a]+1;
				q.push(b);
			}
		}
	}

	for(ll i=1;i<=N;i++) if(c[i]!=1){
		if(1<=v[i] && v[i]<=S) c[i]=-1;
	}

}


void djk(){

    priority_queue<P,vector<P>,greater<P> > q;

    for(ll i=0;i<=N;i++) d[i]=INF;
    d[1]=0;
    q.push(P(0,1));

    while(!q.empty()){
        P p=q.top();  q.pop();
        ll v=p.second;

        if(c[v]==1) continue;
        if(d[v]<p.first) continue;

        for(ll i=0;i<(ll)G[v].size();i++){
        	P x=G[v][i];
        	if(c[x.second]==1) continue;
            if(d[x.second]>d[v]+x.first){
               d[x.second]=d[v]+x.first;
               q.push(P(d[x.second],x.second));
            }
        }
    }

}


int main(void){
	ll i,j,k;
 
	cin.tie(0);  ios_base::sync_with_stdio(false);

	cin >> N >> M >> K >> S >> X >> Y;

	for(i=1;i<=K;i++){
		ll t;
		cin >> t;
		c[t]=1;
	}

	for(i=1;i<=M;i++){
		ll a,b;
		cin >> a >> b;

		g[a].push_back(b);
		g[b].push_back(a);
		e[0][i]=a;
		e[1][i]=b;
	}

	bfs();

	for(i=1;i<=M;i++){
		ll x=e[0][i],y=e[1][i];
		if(y==N){
			G[x].push_back(P(0,y));
			continue;
		}

		if(c[y]==-1) G[x].push_back(P(Y,y));
		if(c[y]==0) G[x].push_back(P(X,y));
		if(c[x]==-1) G[y].push_back(P(Y,x));
		if(c[x]==0) G[y].push_back(P(X,x));
	}


	djk();

	cout << d[N] << endl;


	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 29100
final_rank: 13

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,K,S,X,Y;
const ll INF=1e18;
vector<P> G[100010];
vector<ll> g[100010];
ll d[100010],c[100010],e[2][200010];

void dfs(ll x,ll e){
	if(c[x]!=1) c[x]=-1;
	if(e==S) return;

	for(ll i=0;i<(ll)g[x].size();i++) if(c[g[x][i]]!=-1) dfs(g[x][i],e+1);
}

void djk(){

    priority_queue<P,vector<P>,greater<P> > q;

    for(ll i=0;i<=N;i++) d[i]=INF;
    d[1]=0;
    q.push(P(0,1));

    while(!q.empty()){
        P p=q.top();  q.pop();
        ll v=p.second;

        if(c[v]==1) continue;
        if(d[v]<p.first) continue;

        for(ll i=0;i<(ll)G[v].size();i++){
        	P x=G[v][i];
        	if(c[x.second]==1) continue;
            if(d[x.second]>d[v]+x.first){
               d[x.second]=d[v]+x.first;
               q.push(P(d[x.second],x.second));
            }
        }
    }

}


int main(void){
	ll i,j,k;
 
	cin.tie(0);  ios_base::sync_with_stdio(false);

	cin >> N >> M >> K >> S >> X >> Y;

	for(i=1;i<=K;i++){
		ll t;
		cin >> t;
		c[t]=1;
	}

	for(i=1;i<=M;i++){
		ll a,b;
		cin >> a >> b;

		g[a].push_back(b);
		g[b].push_back(a);
		e[0][i]=a;
		e[1][i]=b;
	}

	for(i=1;i<=N;i++) if(c[i]==1) dfs(i,0);

	for(i=1;i<=M;i++){
		ll x=e[0][i],y=e[1][i];
		if(y==N){
			G[x].push_back(P(0,y));
			continue;
		}

		if(c[y]==-1) G[x].push_back(P(Y,y));
		if(c[y]==0) G[x].push_back(P(X,y));
		if(c[x]==-1) G[y].push_back(P(Y,x));
		if(c[x]==0) G[y].push_back(P(X,x));
	}

	djk();

	cout << d[N] << endl;


	return 0;
}
accuracy: 0.2
time_ms: 20
memory_kb: 18716
final_rank: 20

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,K,S,X,Y;
const ll INF=1e18;
vector<P> G[100010];
vector<ll> g[100010];
ll d[100010],c[100010];

void dfs(ll x,ll e){
	if(c[x]!=1) c[x]=-1;
	if(e==S) return;

	for(ll i=0;i<(ll)g[x].size();i++) if(c[g[x][i]]!=-1) dfs(g[x][i],e+1);
}

void djk(){

    priority_queue<P,vector<P>,greater<P> > q;

    for(ll i=0;i<=N;i++) d[i]=INF;
    d[1]=0;
    q.push(P(0,1));

    while(!q.empty()){
        P p=q.top();  q.pop();
        ll v=p.second;

        if(d[v]<p.first) continue;

        for(ll i=0;i<(ll)G[v].size();i++){
        	P x=G[v][i];
            if(d[x.second]>d[v]+x.first){
               d[x.second]=d[v]+x.first;
               q.push(P(d[x.second],x.second));
            }
        }
    }

}


int main(void){
	ll i,j,k;
 
	cin.tie(0);  ios_base::sync_with_stdio(false);

	cin >> N >> M >> K >> S >> X >> Y;

	for(i=1;i<=K;i++){
		ll t;
		cin >> t;
		c[t]=1;
	}

	for(i=1;i<=M;i++){
		ll a,b;
		cin >> a >> b;

		g[a].push_back(b);
		g[b].push_back(a);

		if(c[a]==1 || c[b]==1) continue;
	    G[a].push_back(P(0,b));
		G[b].push_back(P(0,a));
	}

	for(i=1;i<=N;i++) if(c[i]==1) dfs(i,0);

	for(i=2;i<N;i++){
		if(G[i].empty()) continue;
		for(j=0;j<(ll)G[i].size();j++){
			if(c[i]==0) G[i][j].first=X;
			if(c[i]==-1) G[i][j].first=Y;
		}
	}

	djk();

	cout << d[N] << endl;


	return 0;
}
accuracy: 0.2
time_ms: 20
memory_kb: 16764
final_rank: 18

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,K,S,X,Y;
const ll INF=1e18;
vector<P> G[100010];
vector<ll> g[100010];
ll d[100010],c[100010];

void dfs(ll x,ll e){
	if(c[x]==-1) return;
	if(c[x]==0) c[x]=-1;
	if(e==S) return;

	for(ll i=0;i<(ll)g[x].size();i++) dfs(g[x][i],e+1);
}

void djk(){

    priority_queue<P,vector<P>,greater<P> > q;

    for(ll i=0;i<=N;i++) d[i]=INF;
    d[1]=0;
    q.push(P(0,1));

    while(!q.empty()){
        P p=q.top();  q.pop();
        ll v=p.second;

        if(d[v]<p.first) continue;

        for(ll i=0;i<(ll)G[v].size();i++){
        	P x=G[v][i];
            if(d[x.second]>d[v]+x.first){
               d[x.second]=d[v]+x.first;
               q.push(P(d[x.second],x.second));
            }
        }
    }

}


int main(void){
	ll i,j,k;
 
	cin.tie(0);  ios_base::sync_with_stdio(false);

	cin >> N >> M >> K >> S >> X >> Y;

	for(i=1;i<=K;i++){
		ll t;
		cin >> t;
		c[t]=1;
	}

	for(i=1;i<=M;i++){
		ll a,b;
		cin >> a >> b;

		g[a].push_back(b);
		g[b].push_back(a);

		if(c[a]==1 || c[b]==1) continue;
	    G[a].push_back(P(0,b));
		G[b].push_back(P(0,a));
	}

	for(i=1;i<=N;i++) if(c[i]==1) dfs(i,0);

	for(i=2;i<N;i++){
		if(G[i].empty()) continue;
		for(j=0;j<(ll)G[i].size();j++){
			if(c[i]==0) G[i][j].first=X;
			if(c[i]==-1) G[i][j].first=Y;
		}
	}

	djk();

	cout << d[N] << endl;


	return 0;
}
accuracy: 0.2
time_ms: 20
memory_kb: 16864
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long INF = 9000000007;
typedef pair<long long, long long> Pair;
struct Edge {
    long long to;
    long long cost;
};
void BFS(vector<vector<long long>>&Graph, vector<long long>&Dist, long long start) {
    vector<bool>A(Dist.size(), false);
    queue<long long>Q;
    Q.push(start);
    Dist.at(start) = 0;
    A.at(start) = true;
    while (!Q.empty()) {
        long long v = Q.front(); Q.pop();
        for (auto next_v: Graph[v]) {
            if (!A.at(next_v)) {
                Dist.at(next_v) = min(Dist.at(v) + 1, Dist.at(next_v));
                A.at(next_v) = true; 
                Q.push(next_v);
            }
        }
    }
}
void Dijkstra(const vector<vector<Edge>>& G, long long Start, vector<long long>& Dis) { //ダイクストラ法
	priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> P; //priority_queueを用意.
	Dis.at(Start) = 0; //始点から始点への移動のひつｙ(以下略)
	P.emplace(Dis.at(Start), Start);
	while (!P.empty()) {
		pair<long long, long long> V = P.top(); P.pop();
		long long v = V.second;
		if (Dis.at(v) < V.first) continue;
		for (auto &e : G.at(v)) { //vと隣接する頂点との最短距離を更新.
			if (Dis.at(e.to) > Dis.at(v) + e.cost) {
				Dis.at(e.to) = Dis.at(v) + e.cost;
				P.emplace(Dis.at(e.to), e.to);
			}
		}
	}
}
int main() {
    long long N, M, K, S; cin >> N >> M >> K >> S;
    long long P, Q; cin >> P >> Q;
    vector<long long>Zombie(K);
    vector<bool>danger(N, false);
    for (long long i = 0; i < K; i++) {
        cin >> Zombie.at(i);
        danger.at(Zombie.at(i) - 1) = true;
    }
    vector<Pair>Road(M);
    vector<vector<long long>>Graph(N);
    for (long long i = 0; i < M; i++) {
        cin >> Road.at(i).first >> Road.at(i).second;
        Road.at(i).first--;
        Road.at(i).second--;
        Graph.at(Road.at(i).first).push_back(Road.at(i).second);
        Graph.at(Road.at(i).second).push_back(Road.at(i).first);
    }
    vector<long long>Dist(N, INF);
    for (long long i = 0; i < K; i++) {
        BFS(Graph, Dist, Zombie.at(i) - 1);
    }
    for (long long i = 0; i < N; i++) {
        if (!danger.at(i)) danger.at(i) = (Dist.at(i) <= S);
    }
    vector<vector<Edge>>Graph2(N);
    for (long long i = 0; i < M; i++) {
        Edge E;
        E.to = Road.at(i).second;
        if (Road.at(i).second == N - 1) {
            E.cost = 0;
        }
        else if (Dist.at(Road.at(i).second) == 0) {
            E.cost = INF;
        }
        else E.cost = (danger.at(Road.at(i).second) ? Q : P);
        Graph2.at(Road.at(i).first).push_back(E);
        E.to = Road.at(i).first;
        if (Road.at(i).first == N - 1) {
            E.cost = 0;
        }
        else if (Dist.at(Road.at(i).first) == 0) {
            E.cost = INF;
        }
        else E.cost = (danger.at(Road.at(i).first) ? Q : P);
        Graph2.at(Road.at(i).second).push_back(E);
    }
    vector<long long>Cost(N, INF);
    Dijkstra(Graph2, 0, Cost);
    cout << Cost.at(N - 1) << endl;
}
accuracy: 1
time_ms: 1490
memory_kb: 29544
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
int msb(ll v){return 63-__builtin_clzll(v);}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m,k,s);
    LL(P,Q);
    vector<int> zon(k);
    vector<vector<int>> g(n);
    vector<int> dist1(n,INF);
    vector<ll> dist(n,INF2);
    rpriority_queue<pair<ll,int>> pq;
    queue<int> next;
    rep(i,k){
        in(zon[i]);
        next.push(--zon[i]);
        dist1[zon[i]]=0;
    }
    int u,v;
    rep(i,m){
        in(u,v);
        g[--u].push_back(--v);
        g[v].push_back(u);
    }
    while(!next.empty()){
        v=next.front();
        next.pop();
        for(auto u:g[v]){
            if(dist1[v]+1>=dist1[u])continue;
            dist1[u]=dist1[v]+1;
            next.push(u);
        }
    }
    dist[0]=0;
    pq.push({0,0});
    ll d;
    while(!pq.empty()){
        tie(d,v)=pq.top();
        pq.pop();
        for(auto u:g[v]){
            if(!dist1[u])continue;
            if(dist[v]+(dist1[u]<=s?Q:P)>=dist[u])continue;
            dist[u]=dist[v]+(dist1[u]<=s?Q:P);
            pq.push({dist[u],u});
        }
    }
    out(dist[n-1]-(dist1[n-1]<=s?Q:P));
}
accuracy: 1
time_ms: 40
memory_kb: 10896
final_rank: 5

code_snippet: #include<bits/stdc++.h>

using Int = long long;
using namespace std;
constexpr Int inf = 1e18;
int main(){
    Int N,M,K,S;
    cin  >> N >> M >> K >> S;
    Int P,Q;
    cin >> P >> Q;
    vector<Int>C;
    vector<bool>isSafe(N,true);
    for(int i = 0; i < K; ++i){
        int v; cin >> v; --v;
        C.emplace_back(v);
        isSafe[v] = false;
    }
    vector<vector<Int>>edge(N);
    for(int i = 0; i < M; ++i){
        int s,t; cin >> s >> t;
        --s; --t;
        edge[s].emplace_back(t);
        edge[t].emplace_back(s);
    }
    vector<Int>cost(N,-1);
    priority_queue<pair<Int,int>,vector<pair<Int,int>>>que;
    for(auto c : C) que.emplace(S + 1,c);
    while(not que.empty()){
        auto [tS,v] = que.top(); que.pop();
        for(auto nv : edge[v]){
            if(cost[nv] != -1) continue;
            Int ncost = max(0LL,tS - 1);
            if(not isSafe[nv]) ncost = S + 1;
            if(cost[nv] >= ncost) continue;
            cost[nv] = ncost;
            que.emplace(cost[nv],nv);
        }
    }
    priority_queue<pair<Int,int>,vector<pair<Int,int>>,greater<>>pque;
    vector<Int>path(N,inf);
    path[0] = 0;
    pque.emplace(0,path[0]);
    while(not pque.empty()){
        auto [cd,cv] = pque.top(); pque.pop();
        for(auto  nv : edge[cv]){
            if(path[nv] != inf or path[nv] <= cd or (not isSafe[nv]))continue;
            Int cst = (cost[nv] > 0 ? Q : P);
            path[nv] = cst  + cd;
            pque.emplace(path[nv],nv);
        }
    }
    cout << path[ N - 1] - (cost[N - 1] > 0 ? Q : P) << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 13916
final_rank: 8

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;

  BIT(int n){
    N = n;
    node.resize(N+10);
  }

  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = calc_mod(mt()) % 100000 + 1000;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};
template <typename Monoid>
struct SegmentTree{

  int N;
  vector<Monoid> node;
  Monoid Unit;
  function<Monoid(Monoid, Monoid)> f;

  SegmentTree(vector<Monoid> v, const function<Monoid(Monoid, Monoid)> f, const Monoid &Unit): f(f), Unit(Unit){
    int sz_ = v.size();
    N = 1;
    while(N < sz_) N *= 2;

    node.assign(2*N, Unit);
    for(int i=0; i<sz_; i++) node[i+N-1] = v[i];
    for(int i=N-2; i>=0; i--) node[i] = f(node[2*i+1], node[2*i+2]);
  }

  void update(int k, const Monoid &x) {
    k += N-1;
    node[k] = x;
    while(k > 0){
      k = (k-1)/2;
      node[k] = f(node[2*k+1], node[2*k+2]);
    }
  }

  Monoid query(int a, int b, int k=0, int l = 0, int r=-1){
    if(r < 0) r = N;
    if(r <= a || b <= l) return Unit;
    if(a <= l && r <= b) return node[k];
    else{
      Monoid vl = query(a, b, 2*k+1, l, (l+r)/2);
      Monoid vr = query(a, b, 2*k+2, (l+r)/2, r);
      return f(vl, vr);
    }
  }

  inline Monoid operator[](int a) { return query(a, a + 1); }
};

vector<vector<int>> g(101010);
ll dist[101010];
int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  ll N, M, K, S; cin >> N >> M >> K >> S;
  ll P, Q; cin >> P >> Q;

  vector<int> ok(N, 1e9);
  queue<int> q;
  REP(i,K) {
    int c; cin >> c;
    c--;
    q.push(c);
    ok[c] = 0;
  }
  REP(i,M) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  while(q.size()) {
    int v = q.front(); q.pop();
    
    for(auto u: g[v]) {
      if(ok[u] > ok[v] + 1) {
        ok[u] = ok[v] + 1;
        q.push(u);
      }
    }
  }
  REP(i,N) dist[i] = (1LL<<60);
  dist[0] = 0;
  priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
  pq.push({0, 0});
  while(pq.size()) {
    auto[cost, v] = pq.top(); pq.pop();
    if(dist[v] < cost) continue;
    for(auto u: g[v]) {
      if(ok[u] == 0) continue;
      ll t = P;
      if(ok[u] <= S) t = Q;
      if(u == N-1) t = 0;
      if(dist[u] > dist[v] + t) {
        dist[u] = dist[v] + t;
        pq.push({dist[u], u});
      }
    }
  }
  cout << dist[N-1] << endl;
  

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10792
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)

struct Edge{
    int to;
    lint cost;
    
    Edge(int to, lint cost): to(to), cost(cost) {}
};
using Graph = vector<vector<Edge>>;

const lint INF = 1e18;
vector<lint> dijkstra(Graph g, vector<int> s){
    int n = int(g.size());
    using P = pair<lint, int>;
    
    vector<lint> dist(n, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    for(int v: s){
        dist[v] = 0;
        que.push({0, v});
    }
    
    while(!que.empty()){
        auto top = que.top();
        que.pop();
        int at = top.second;
        lint cost = top.first;
        if(dist[at] < cost){
            continue;
        }
        
        for(auto e: g[at]){
            int to = e.to;
            lint ncost = cost + e.cost;
            if(dist[to] > ncost){
                dist[to] = ncost;
                que.push({ncost, to});
            }
        }
    }
    
    return dist;
}

int main(){
    int n, m, k, s;
    cin >> n >> m >> k >> s;
    lint p, q;
    cin >> p >> q;
    
    vector<int> zombie(k);
    vector<bool> is_zombie(n, false);
    rep(i, k){
        cin >> zombie[i];
        zombie[i]--;
        
        is_zombie[zombie[i]] = true;
    }
    
    Graph g(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(Edge(b, 1));
        g[b].push_back(Edge(a, 1));
    }
    
    vector<lint> dist = dijkstra(g, zombie);
    vector<bool> dangerous(n);
    rep(i, n) dangerous[i] = (dist[i] <= s);
    
    Graph g2(n);
    rep(from, n){
        for(auto e: g[from]){
            int to = e.to;
            
            lint cost = (to == n - 1 ? 0 :
                         is_zombie[to] ? INF :
                         dangerous[to] ? q : p);
            g2[from].push_back({to, cost});
        }
    }
    
    auto ans = dijkstra(g2, {0});
    cout << ans[n - 1] << endl;
    
//    rep(i, n) cout << dist[i] << " ";
//    cout << endl;
//    rep(i, n) cout << ans[i] << " ";
//    cout << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 38692
final_rank: 15