結果

問題 No.2431 Viral Hotel
ユーザー polylogK
提出日時 2023-09-28 18:14:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,729 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 202,452 KB
最終ジャッジ日時 2025-02-17 02:48:24
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d%d%d%d", &n, &k, &m, &p);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:38:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     for (auto& v : s) scanf("%d", &v);
      |                       ~~~~~^~~~~~~~~~
main.cpp:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~

ソースコード

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});
    }

    int ans = 0;
    while (!qu.empty()) {
        const auto [now, v] = qu.top();
        qu.pop();
        if (imm[v] == 0) continue;

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

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

    printf("%d\n", ans);
    return 0;
}
0