結果
問題 | No.2431 Viral Hotel |
ユーザー |
|
提出日時 | 2023-08-18 22:53:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 1,090 bytes |
コンパイル時間 | 1,102 ms |
コンパイル使用メモリ | 83,896 KB |
実行使用メモリ | 14,488 KB |
最終ジャッジ日時 | 2024-11-28 09:10:56 |
合計ジャッジ時間 | 5,981 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
#include<iostream> #include<vector> #include<queue> #include<utility> using namespace std; int main() { int N,K,M,P,u,v,x; cin >> N >> K >> M >> P; vector<vector<int>> G(N); while(M--) { cin >> u >> v; G[u-1].push_back(v-1); G[v-1].push_back(u-1); } vector<int> s(N); for(int i=0;i<N;i++)cin >> s[i]; priority_queue<pair<long long,pair<int,int>>,vector<pair<long long,pair<int,int>>>,greater<pair<long long,pair<int,int>>>> q; while(K--) { cin >> x; q.push({0,{x-1,x-1}}); } int ans = 0; vector<long long> t(N,-1),t2(N,1ll<<60); while(!q.empty()) { pair<long long,pair<int,int>> p = q.top(); q.pop(); if(p.first > t2[p.second.first])continue; if(t[p.second.second] < 0) { for(int i=0;i<G[p.second.second].size();i++) { q.push({p.first+s[p.second.second],{p.second.second,G[p.second.second][i]}}); } t[p.second.second] = p.first; } else if(t[p.second.second] + P > p.first && t2[p.second.second] == 1ll<<60) { ans++; t2[p.second.second] = p.first; } } cout << ans << endl; }