結果

問題 No.2431 Viral Hotel
ユーザー 👑 potato167potato167
提出日時 2023-08-16 01:47:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 2,306 ms
コンパイル使用メモリ 211,676 KB
実行使用メモリ 12,520 KB
最終ジャッジ日時 2024-05-03 11:38:14
合計ジャッジ時間 8,206 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
9,876 KB
testcase_01 AC 138 ms
9,496 KB
testcase_02 AC 145 ms
9,808 KB
testcase_03 AC 159 ms
10,480 KB
testcase_04 AC 171 ms
11,432 KB
testcase_05 AC 190 ms
11,308 KB
testcase_06 AC 44 ms
5,376 KB
testcase_07 AC 44 ms
5,376 KB
testcase_08 AC 44 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 209 ms
12,520 KB
testcase_13 AC 157 ms
10,096 KB
testcase_14 AC 82 ms
7,296 KB
testcase_15 AC 32 ms
5,376 KB
testcase_16 AC 98 ms
9,792 KB
testcase_17 AC 67 ms
6,272 KB
testcase_18 AC 162 ms
11,176 KB
testcase_19 AC 104 ms
8,732 KB
testcase_20 AC 47 ms
6,400 KB
testcase_21 AC 37 ms
5,480 KB
testcase_22 AC 104 ms
8,112 KB
testcase_23 AC 108 ms
7,912 KB
testcase_24 AC 64 ms
6,912 KB
testcase_25 AC 147 ms
9,344 KB
testcase_26 AC 87 ms
8,296 KB
testcase_27 AC 97 ms
7,680 KB
testcase_28 AC 81 ms
7,040 KB
testcase_29 AC 79 ms
6,784 KB
testcase_30 AC 96 ms
7,040 KB
testcase_31 AC 123 ms
9,656 KB
testcase_32 AC 37 ms
5,376 KB
testcase_33 AC 77 ms
6,528 KB
testcase_34 AC 8 ms
5,376 KB
testcase_35 AC 25 ms
5,376 KB
testcase_36 AC 136 ms
9,820 KB
testcase_37 AC 96 ms
7,884 KB
testcase_38 AC 44 ms
6,272 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 182 ms
12,328 KB
testcase_44 AC 116 ms
8,780 KB
testcase_45 AC 84 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(p) p.begin(),p.end()
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
const int mod=998244353;

int main(){
	int N,K,M,P;
	cin>>N>>K>>M>>P;
	vector<vector<int>> G(N);
	rep(i,0,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	struct event
	{
		int type;
		int time;
		int ind;
	};
	auto comp_event=[&](event l,event r)->bool{
		if(l.time==r.time) return l.type>r.type;
		return l.time>r.time;
	};
	vector<int> p(N);
	priority_queue<event,vector<event>,std::function<bool(event,event)>> pq(comp_event);
	vector<int> S(N);
	rep(i,0,N) cin>>S[i];
	rep(i,0,K){
		int x;
		cin>>x;
		x--;
		pq.push({1,P,x});
		pq.push({2,S[x],x});
		p[x]++;
	}
	int ans=0;
	while(!pq.empty()){
		auto tmp=pq.top();
		pq.pop();
		//cout<<tmp.type<<" "<<tmp.time<<" "<<tmp.ind+1<<endl;
		if(tmp.type==1){
			if(p[tmp.ind]!=-1) p[tmp.ind]=-2;
		}
		if(tmp.type==2){
			if(p[tmp.ind]==-1) continue;
			for(auto x:G[tmp.ind]){
				if(p[x]==-1||p[x]==-2) continue;
				p[x]++;
				if(p[x]==1){
					pq.push({2,tmp.time+S[x],x});
					pq.push({1,tmp.time+P,x});
				}
				if(p[x]==2){
					pq.push({3,tmp.time,x});
				}
			}
		}
		if(tmp.type==3){
			ans++;
			p[tmp.ind]=-1;
		}
	}
	cout<<ans<<"\n";
}
0