結果

問題 No.2431 Viral Hotel
ユーザー nono00
提出日時 2023-08-19 01:12:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,289 bytes
コンパイル時間 3,268 ms
コンパイル使用メモリ 267,872 KB
実行使用メモリ 26,408 KB
最終ジャッジ日時 2024-11-28 13:34:25
合計ジャッジ時間 9,585 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 38
権限があれば一括ダウンロードができます

ソースコード

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