結果

問題 No.2431 Viral Hotel
ユーザー polylogKpolylogK
提出日時 2023-09-28 18:25:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 209,480 KB
実行使用メモリ 10,572 KB
最終ジャッジ日時 2023-09-28 18:25:19
合計ジャッジ時間 7,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
8,860 KB
testcase_01 AC 61 ms
8,544 KB
testcase_02 AC 67 ms
8,612 KB
testcase_03 AC 83 ms
10,288 KB
testcase_04 AC 85 ms
9,992 KB
testcase_05 AC 95 ms
10,572 KB
testcase_06 AC 18 ms
4,552 KB
testcase_07 AC 18 ms
4,516 KB
testcase_08 AC 18 ms
4,512 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 99 ms
10,256 KB
testcase_13 AC 91 ms
9,748 KB
testcase_14 AC 40 ms
7,040 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 46 ms
7,708 KB
testcase_17 AC 32 ms
5,756 KB
testcase_18 AC 78 ms
8,900 KB
testcase_19 AC 49 ms
7,596 KB
testcase_20 AC 25 ms
6,228 KB
testcase_21 AC 18 ms
4,672 KB
testcase_22 AC 51 ms
6,800 KB
testcase_23 AC 59 ms
7,572 KB
testcase_24 AC 34 ms
6,900 KB
testcase_25 AC 76 ms
8,964 KB
testcase_26 AC 46 ms
7,672 KB
testcase_27 AC 52 ms
7,224 KB
testcase_28 AC 40 ms
6,376 KB
testcase_29 AC 40 ms
6,308 KB
testcase_30 AC 50 ms
6,540 KB
testcase_31 AC 66 ms
8,816 KB
testcase_32 AC 17 ms
4,664 KB
testcase_33 AC 37 ms
6,224 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 13 ms
4,580 KB
testcase_36 AC 70 ms
9,140 KB
testcase_37 AC 45 ms
6,700 KB
testcase_38 AC 24 ms
6,088 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 78 ms
10,004 KB
testcase_44 AC 49 ms
7,572 KB
testcase_45 AC 37 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#if defined(DONLINE_JUDGE)
#define NDEBUG
#elif defined(ONLINE_JUDGE)
#define NDEBUG
#endif

template <typename T>
std::vector<T> make_v(size_t a) {
    return std::vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main() {
    int n, k, m, p;
    scanf("%d%d%d%d", &n, &k, &m, &p);
    std::vector<std::vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a;
        --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }
    std::vector<int> s(n);
    for (auto& v : s) scanf("%d", &v);

    using P = std::pair<int, int>;  // (time, vertex)
    std::priority_queue<P, std::vector<P>, std::greater<P>> qu;

    std::vector<int> imm(n, -1);
    for (int i = 0; i < k; ++i) {
        int x;
        scanf("%d", &x);
        --x;

        imm[x] = p;
        qu.push({s[x], x});
    }

    std::vector<int> ban(n, -1);
    while (!qu.empty()) {
        const auto [now, v] = qu.top();
        qu.pop();
        if (ban[v] != -1 and ban[v] < now) continue;

        for (int to : g[v]) {
            if (imm[to] == -1) {
                imm[to] = now + p;
            } else if (now < imm[to]) {
                imm[to] = 0;
                ban[to] = now;
                continue;
            } else if (imm[to] <= now) {
                continue;
            }

            qu.push({now + s[to], to});
        }
    }

    const int ans = std::count(ban.begin(), ban.end(), -1);
    printf("%d\n", n - ans);
    return 0;
}
0