結果

問題 No.2431 Viral Hotel
ユーザー Nzt3Nzt3
提出日時 2023-08-19 15:36:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 210,240 KB
実行使用メモリ 11,552 KB
最終ジャッジ日時 2024-05-06 22:41:20
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
9,556 KB
testcase_01 AC 91 ms
9,088 KB
testcase_02 AC 103 ms
9,216 KB
testcase_03 AC 120 ms
10,880 KB
testcase_04 AC 119 ms
10,752 KB
testcase_05 AC 136 ms
11,348 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 17 ms
5,376 KB
testcase_08 AC 17 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 149 ms
11,536 KB
testcase_13 AC 127 ms
10,368 KB
testcase_14 AC 54 ms
7,424 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 66 ms
8,776 KB
testcase_17 AC 45 ms
6,272 KB
testcase_18 AC 109 ms
10,164 KB
testcase_19 AC 70 ms
8,448 KB
testcase_20 AC 32 ms
6,400 KB
testcase_21 AC 25 ms
5,376 KB
testcase_22 AC 72 ms
7,680 KB
testcase_23 AC 81 ms
7,808 KB
testcase_24 AC 44 ms
7,168 KB
testcase_25 AC 109 ms
9,600 KB
testcase_26 AC 63 ms
8,192 KB
testcase_27 AC 73 ms
7,808 KB
testcase_28 AC 58 ms
7,040 KB
testcase_29 AC 59 ms
6,656 KB
testcase_30 AC 63 ms
6,912 KB
testcase_31 AC 89 ms
9,344 KB
testcase_32 AC 24 ms
5,376 KB
testcase_33 AC 52 ms
6,400 KB
testcase_34 AC 5 ms
5,376 KB
testcase_35 AC 16 ms
5,376 KB
testcase_36 AC 96 ms
9,456 KB
testcase_37 AC 63 ms
7,296 KB
testcase_38 AC 28 ms
6,400 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 118 ms
11,552 KB
testcase_44 AC 74 ms
8,320 KB
testcase_45 AC 55 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,K,M,P;
  cin>>N>>K>>M>>P;
  vector<vector<int>>G(N);
  for(int i=0;i<M;i++){
    int A,B;
    cin>>A>>B;
    --A,--B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  vector<int>S(N);
  for(int &i:S)cin>>i;
  vector<int>dist(N,(int)1e9),v_cnt(N,0),owari(N,0);
  priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>>pq;
  for(int i=0;i<K;i++){
    int T;
    cin>>T;
    --T;
    dist[T]=0;
    pq.push({0,0,T});
  }
  while(pq.size()){
    int v=pq.top()[2],d=pq.top()[0],t=pq.top()[1];
    pq.pop();
    if(owari[v])continue;
    if(t==0){
      if(d<dist[v]+P){
        v_cnt[v]+=1;
      }
      if(v_cnt[v]>=2){
        pq.push({d,2,v});
      }
      if(d>dist[v])continue;
      pq.push({d+S[v],1,v});
    }else if(t==1){
      for(int i:G[v]){
        if(dist[i]>d){
          dist[i]=d;
        }
        if(dist[i]+P>d){
          pq.push({d,0,i}); 
        }
      }
    }else if(t==2){
      owari[v]=1;
    }
  }
  int ans=accumulate(owari.begin(),owari.end(),0);
  cout<<ans<<'\n';
}
0