結果

問題 No.2431 Viral Hotel
ユーザー 👑 emthrmemthrm
提出日時 2023-08-18 23:49:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 2,948 ms
コンパイル使用メモリ 264,000 KB
実行使用メモリ 21,504 KB
最終ジャッジ日時 2024-05-06 06:39:23
合計ジャッジ時間 7,144 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
14,720 KB
testcase_01 AC 94 ms
13,312 KB
testcase_02 AC 107 ms
12,416 KB
testcase_03 AC 113 ms
13,440 KB
testcase_04 AC 122 ms
14,592 KB
testcase_05 AC 143 ms
17,664 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 17 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 158 ms
21,504 KB
testcase_13 AC 114 ms
12,800 KB
testcase_14 AC 55 ms
9,600 KB
testcase_15 AC 19 ms
5,772 KB
testcase_16 AC 78 ms
14,976 KB
testcase_17 AC 44 ms
8,576 KB
testcase_18 AC 114 ms
16,640 KB
testcase_19 AC 81 ms
12,672 KB
testcase_20 AC 31 ms
6,784 KB
testcase_21 AC 26 ms
6,912 KB
testcase_22 AC 71 ms
10,752 KB
testcase_23 AC 73 ms
10,112 KB
testcase_24 AC 41 ms
8,576 KB
testcase_25 AC 93 ms
12,288 KB
testcase_26 AC 59 ms
9,984 KB
testcase_27 AC 69 ms
10,240 KB
testcase_28 AC 56 ms
9,216 KB
testcase_29 AC 53 ms
8,448 KB
testcase_30 AC 59 ms
9,728 KB
testcase_31 AC 89 ms
12,544 KB
testcase_32 AC 25 ms
6,144 KB
testcase_33 AC 52 ms
8,576 KB
testcase_34 AC 6 ms
5,376 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 110 ms
15,616 KB
testcase_37 AC 69 ms
12,160 KB
testcase_38 AC 24 ms
6,528 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 131 ms
19,456 KB
testcase_44 AC 84 ms
12,928 KB
testcase_45 AC 58 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k, m, p; cin >> n >> k >> m >> p;
  vector<vector<int>> graph(n);
  while (m--) {
    int u, v; cin >> u >> v; --u; --v;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  vector<int> s(n); REP(i, n) cin >> s[i];
  vector<int> infected(n, 0);
  set<tuple<ll, int, int>> days;  // day, recover/spread/goodbye, room
  while (k--) {
    int x; cin >> x; --x;
    infected[x] = 1;
    days.emplace(s[x], 1, x);
    days.emplace(p, 0, x);
  }
  while (!days.empty()) {
    const auto [d, type, room] = *days.begin();
    days.erase(days.begin());
    if (infected[room] == -1) continue;
    if (type == 0) {
      infected[room] = -2;
    } else if (type == 1) {
      for (const int e : graph[room]) {
        if (infected[e] > 0) {
          ++infected[e];
          days.emplace(d, 2, e);
        } else if (infected[e] == 0) {
          infected[e] = 1;
          days.emplace(d + s[e], 1, e);
          days.emplace(d + p, 0, e);
        }
      }
    } else {
      infected[room] = -1;
    }
  }
  cout << ranges::count(infected, -1) << '\n';
  return 0;
}
0