結果

問題 No.2431 Viral Hotel
ユーザー momoyuumomoyuu
提出日時 2023-08-18 21:57:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 4,171 ms
コンパイル使用メモリ 257,116 KB
実行使用メモリ 13,832 KB
最終ジャッジ日時 2023-08-18 21:57:25
合計ジャッジ時間 9,487 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
10,136 KB
testcase_01 AC 104 ms
9,660 KB
testcase_02 AC 143 ms
10,080 KB
testcase_03 AC 132 ms
10,692 KB
testcase_04 AC 136 ms
11,388 KB
testcase_05 AC 164 ms
11,520 KB
testcase_06 AC 38 ms
4,380 KB
testcase_07 AC 37 ms
4,380 KB
testcase_08 AC 39 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 165 ms
13,832 KB
testcase_13 AC 151 ms
9,948 KB
testcase_14 AC 61 ms
7,532 KB
testcase_15 AC 26 ms
4,728 KB
testcase_16 AC 74 ms
10,504 KB
testcase_17 AC 52 ms
6,356 KB
testcase_18 AC 130 ms
12,612 KB
testcase_19 AC 80 ms
8,812 KB
testcase_20 AC 36 ms
6,192 KB
testcase_21 AC 30 ms
5,576 KB
testcase_22 AC 83 ms
8,192 KB
testcase_23 AC 93 ms
7,824 KB
testcase_24 AC 52 ms
6,948 KB
testcase_25 AC 118 ms
9,292 KB
testcase_26 AC 72 ms
8,088 KB
testcase_27 AC 85 ms
7,580 KB
testcase_28 AC 67 ms
7,004 KB
testcase_29 AC 68 ms
7,012 KB
testcase_30 AC 75 ms
7,280 KB
testcase_31 AC 98 ms
9,924 KB
testcase_32 AC 30 ms
4,872 KB
testcase_33 AC 61 ms
6,444 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 20 ms
4,656 KB
testcase_36 AC 120 ms
9,832 KB
testcase_37 AC 86 ms
8,020 KB
testcase_38 AC 40 ms
6,172 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 142 ms
13,356 KB
testcase_44 AC 91 ms
8,920 KB
testcase_45 AC 72 ms
7,396 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