結果

問題 No.2431 Viral Hotel
ユーザー momoyuumomoyuu
提出日時 2023-08-18 21:57:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 2,702 ms
コンパイル使用メモリ 257,620 KB
実行使用メモリ 13,420 KB
最終ジャッジ日時 2024-05-06 03:58:25
合計ジャッジ時間 7,628 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
10,304 KB
testcase_01 AC 100 ms
9,760 KB
testcase_02 AC 110 ms
10,448 KB
testcase_03 AC 124 ms
10,676 KB
testcase_04 AC 127 ms
11,820 KB
testcase_05 AC 140 ms
11,820 KB
testcase_06 AC 40 ms
5,376 KB
testcase_07 AC 39 ms
5,376 KB
testcase_08 AC 40 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 155 ms
13,420 KB
testcase_13 AC 121 ms
10,340 KB
testcase_14 AC 59 ms
7,656 KB
testcase_15 AC 25 ms
5,376 KB
testcase_16 AC 77 ms
10,812 KB
testcase_17 AC 51 ms
6,500 KB
testcase_18 AC 124 ms
12,456 KB
testcase_19 AC 75 ms
9,240 KB
testcase_20 AC 37 ms
6,400 KB
testcase_21 AC 30 ms
5,928 KB
testcase_22 AC 80 ms
8,628 KB
testcase_23 AC 86 ms
8,236 KB
testcase_24 AC 49 ms
7,040 KB
testcase_25 AC 107 ms
9,820 KB
testcase_26 AC 71 ms
8,488 KB
testcase_27 AC 80 ms
7,900 KB
testcase_28 AC 63 ms
7,268 KB
testcase_29 AC 62 ms
7,128 KB
testcase_30 AC 72 ms
7,504 KB
testcase_31 AC 93 ms
10,172 KB
testcase_32 AC 31 ms
5,376 KB
testcase_33 AC 59 ms
6,840 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 21 ms
5,376 KB
testcase_36 AC 112 ms
10,104 KB
testcase_37 AC 77 ms
8,388 KB
testcase_38 AC 38 ms
6,400 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 148 ms
13,352 KB
testcase_44 AC 93 ms
9,292 KB
testcase_45 AC 70 ms
7,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ll n,k,m,p;
    cin>>n>>k>>m>>p;
    vector<vector<int>> g(n);
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> now(n,0);
    vector<int> s(n);
    for(int i = 0;i<n;i++) cin>>s[i];
    using dat = pair<ll,pair<int,int>>;
    priority_queue<dat,vector<dat>,greater<dat>> que;
    for(int i = 0;i<k;i++){
        int x;
        cin>>x;
        x--;
        now[x] = 1;
        que.push(make_pair(s[x],make_pair(1,x)));
        que.push(make_pair(p,make_pair(0,x)));
    }
    int ans = 0;
    while(que.size()){
        auto nown = que.top();
        que.pop();
        ll d = nown.first;
        int t = nown.second.first;
        int ni = nown.second.second;
        if(t==1){
            if(now[ni]<0){
                if(-now[ni]<d) continue;
            }
            for(auto&to:g[ni]){
                if(now[to]==0){
                    now[to] = 1;
                    que.push(make_pair(d+s[to],make_pair(1,to)));
                    que.push(make_pair(d+p,make_pair(0,to)));
                }else if(now[to]==1){
                    now[to] = -d;
                    ans++;
                }
            }
        }else if(t==0){
            if(now[ni]<0) continue;
            now[ni] = 2;
        }
    }
    cout<<ans<<endl;

}

0