結果
| 問題 |
No.2431 Viral Hotel
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2023-08-16 01:47:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 2,000 ms |
| コード長 | 1,289 bytes |
| コンパイル時間 | 2,096 ms |
| コンパイル使用メモリ | 204,380 KB |
| 最終ジャッジ日時 | 2025-02-16 08:36:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
#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";
}
potato167