結果

問題 No.2431 Viral Hotel
ユーザー noya2noya2
提出日時 2023-08-14 21:56:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,487 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 211,624 KB
実行使用メモリ 14,204 KB
最終ジャッジ日時 2024-05-02 18:41:20
合計ジャッジ時間 7,095 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
10,996 KB
testcase_01 AC 120 ms
10,564 KB
testcase_02 AC 129 ms
10,896 KB
testcase_03 AC 150 ms
11,580 KB
testcase_04 AC 157 ms
12,604 KB
testcase_05 AC 171 ms
12,604 KB
testcase_06 AC 39 ms
5,376 KB
testcase_07 AC 39 ms
5,376 KB
testcase_08 AC 39 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 187 ms
14,204 KB
testcase_13 AC 153 ms
11,124 KB
testcase_14 AC 71 ms
8,128 KB
testcase_15 AC 30 ms
5,376 KB
testcase_16 AC 88 ms
11,408 KB
testcase_17 AC 61 ms
6,912 KB
testcase_18 AC 143 ms
12,812 KB
testcase_19 AC 90 ms
9,812 KB
testcase_20 AC 41 ms
6,656 KB
testcase_21 AC 39 ms
5,756 KB
testcase_22 AC 95 ms
8,908 KB
testcase_23 AC 100 ms
8,716 KB
testcase_24 AC 58 ms
7,552 KB
testcase_25 AC 133 ms
10,396 KB
testcase_26 AC 81 ms
8,956 KB
testcase_27 AC 93 ms
8,504 KB
testcase_28 AC 71 ms
7,644 KB
testcase_29 AC 74 ms
7,472 KB
testcase_30 AC 85 ms
7,748 KB
testcase_31 AC 117 ms
10,736 KB
testcase_32 AC 34 ms
5,376 KB
testcase_33 AC 70 ms
7,136 KB
testcase_34 AC 8 ms
5,376 KB
testcase_35 AC 25 ms
5,376 KB
testcase_36 AC 123 ms
10,892 KB
testcase_37 AC 84 ms
8,780 KB
testcase_38 AC 39 ms
6,784 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 168 ms
13,952 KB
testcase_44 AC 106 ms
9,732 KB
testcase_45 AC 81 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n, k, m, p; cin >> n >> k >> m >> p;
    vector<vector<int>> g(n);
    while (m--){
        int u, v; cin >> u >> v; u--, v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    vector<ll> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    /*
        0 : none
        1 : infected
        2 : cured
        3 : infected again
    */
    vector<ll> status(n,0);
    priority_queue<pli,vector<pli>,greater<pli>> pque;
    auto id = [&](ll t, int type){
        return t * 3 + type;
    };
    while (k--){
        int x; cin >> x; x--;
        pque.push(pli(id(0,2),x));
    }
    int ans = 0;
    while (!pque.empty()){
        auto [tt, v] = pque.top(); pque.pop();
        ll t = tt / 3;
        int type = tt % 3;
        if (type == 0){
            if (status[v] == 3) continue;
            status[v] = 2;
        }
        if (type == 1){
            if (status[v] == 3) continue;
            for (int u : g[v]){
                pque.push(pli(id(t,2),u));
            }
        }
        if (type == 2){
            if (status[v] >= 2) continue;
            if (status[v] == 0){
                status[v] = 1;
                pque.push(pli(id(t+s[v],1),v));
                pque.push(pli(id(t+p,0),v));
            }
            else {
                ans++;
                status[v] = 3;
            }
        }
    }
    cout << ans << endl;
}
0