結果

問題 No.2431 Viral Hotel
ユーザー nono00nono00
提出日時 2023-08-19 01:12:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,289 bytes
コンパイル時間 3,991 ms
コンパイル使用メモリ 268,252 KB
実行使用メモリ 26,540 KB
最終ジャッジ日時 2024-05-06 08:21:35
合計ジャッジ時間 9,545 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 7 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
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 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

// type 1: 回復
// type 2: 感染
struct Event {
    long long time;
    long long type;
    long long index;
    Event(long long time, long long type, long long index): time(time), type(type), index(index) {}
};

bool operator<(const Event& lhs, const Event& rhs) {
    if (lhs.time == rhs.time and lhs.type == rhs.type) return lhs.index > rhs.index;
    if (lhs.time == rhs.time) return lhs.type > rhs.type;
    return lhs.time > rhs.time;
}

void solve() {
    int N, M, K, P;
    std::cin >> N >> K >> M >> P;
    std::vector graph(N, std::vector<int>());
    for (int i = 0; i < M; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    std::vector<long long> s(N);
    for (int i = 0; i < N; i++) std::cin >> s[i];
    std::priority_queue<Event> events;
    std::vector<bool> kansen(N);
    std::vector<bool> keneki(N);
    std::vector<bool> meneki(N);
    for (int i = 0; i < K; i++) {
        int x;
        std::cin >> x;
        x--;
        kansen[x] = true;
        events.emplace(P, 1, x);
        events.emplace(s[x], 2, x);
    }

    std::set<Event> used;
    while (not events.empty()) {
        auto event = events.top();
        events.pop();
        if (used.contains(event)) continue;
        used.insert(event);
        auto [time, type, u] = event;
        // std::cerr << time << ' ' << type << ' ' << u << std::endl;
        if (keneki[u]) continue;
        if (type == 1) {
            meneki[u] = true;
        } else {
            for (int v: graph[u]) {
                if (meneki[v]) continue;
                if (keneki[v]) continue;
                if (not kansen[v]) {
                    events.emplace(time + P, 1, v);
                    events.emplace(time + s[v], 2, v);
                    kansen[v] = true;
                } else {
                    keneki[v] = true;
                }
            }
        }
    }

    std::cout << std::accumulate(keneki.begin(), keneki.end(), 0LL) << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    //  std::cin >> t;
    while (t--) nono::solve();
}
0