結果

問題 No.2431 Viral Hotel
ユーザー cho435
提出日時 2023-08-21 22:56:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 4,224 ms
コンパイル使用メモリ 259,596 KB
最終ジャッジ日時 2025-02-16 12:08:50
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int n,k,m,p;
	cin>>n>>k>>m>>p;
	vector<vector<int>> g(n);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--; v--;
		g.at(u).push_back(v);
		g.at(v).push_back(u);
	}
	vector<int> s(n);
	rep(i,n) cin>>s.at(i);
	priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> pq;
	rep(i,k){
		int x;
		cin>>x;
		x--;
		pq.push({0,2,x});
	}
	vector<int> st(n,-1);
	while(!pq.empty()){
		auto[t,flg,x]=pq.top();
		pq.pop();
		if(st.at(x)==2) continue;
		if(flg==2){
			if(st.at(x)==0){
				st.at(x)=2;
				continue;
			}
			if(st.at(x)==1) continue;
			st.at(x)=0;
			pq.push({t+s.at(x),1,x});
			pq.push({t+p,0,x});
		}
		if(flg==1){
			for(int nx:g.at(x)){
				if(st.at(nx)>0) continue;
				pq.push({t,2,nx});
			}
		}
		if(flg==0){
			st.at(x)=1;
		}
	}
	int ans=0;
	rep(i,n) if(st.at(i)==2) ans++;
	cout<<ans<<endl;
}
0