Submission #8344819


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, K, S, P, Q;
vector<int> E[101010];
bool zombie[101010];
//---------------------------------------------------------------------------------------------------
bool danger[101010];
int dist[101010];
void bfs() {
	queue<int> que;

	rep(i, 0, N) {
		if (zombie[i]) {
			dist[i] = 0;
			que.push(i);
		}
		else dist[i] = -1;
	}

	while (!que.empty()) {
		int cu = que.front(); que.pop();

		fore(to, E[cu]) if (dist[to] < 0) {
			dist[to] = dist[cu] + 1;
			que.push(to);
		}
	}

	rep(i, 0, N) if (1 <= dist[i] and dist[i] <= S) danger[i] = true;
}
//---------------------------------------------------------------------------------------------------
bool vis[101010];
ll D[101010];
ll dijk() {
	rep(i, 0, N) D[i] = infl;
	rep(i, 0, N) vis[i] = false;

	min_priority_queue<pair<ll, int>> que;

	D[0] = 0;
	que.push({ 0, 0 });

	while (!que.empty()) {
		auto q = que.top(); que.pop();

		ll cst = q.first;
		int cu = q.second;

		if (cu == N - 1) {
			if (danger[cu]) return cst - Q;
			else return cst - P;
		}

		if (vis[cu]) continue;
		vis[cu] = 1;

		fore(to, E[cu]) {
			if (zombie[to]) continue;

			ll cst2 = cst;

			if (danger[to]) cst2 += Q;
			else cst2 += P;
			
			if (chmin(D[to], cst2)) que.push({ D[to], to });
		}
	}

	return -1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K >> S >> P >> Q;
	rep(i, 0, K) {
		int c; cin >> c; c--;
		zombie[c] = true;
	}
	rep(i, 0, M) {
		int a, b; cin >> a >> b; a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	bfs();
	cout << dijk() << endl;
}





Submission Info

Submission Time
Task E - ゾンビ島 (Zombie Island)
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3065 Byte
Status AC
Exec Time 71 ms
Memory 8448 KB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 2 ms 2688 KB
data2 AC 32 ms 7040 KB
data3 AC 4 ms 2816 KB
data4 AC 71 ms 8448 KB
data5 AC 61 ms 7296 KB