結果
| 問題 |
No.2431 Viral Hotel
|
| コンテスト | |
| ユーザー |
nono00
|
| 提出日時 | 2023-08-19 01:18:25 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,568 bytes |
| コンパイル時間 | 3,506 ms |
| コンパイル使用メモリ | 269,152 KB |
| 実行使用メモリ | 26,424 KB |
| 最終ジャッジ日時 | 2024-11-28 13:40:59 |
| 合計ジャッジ時間 | 10,224 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 38 |
ソースコード
#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;
std::vector<int> keneki_stack;
int prev = -1;
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 (prev != time) {
while (!keneki_stack.empty()) {
int v = keneki_stack.back();
keneki_stack.pop_back();
keneki[v] = true;
}
}
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_stack.push_back(v);
}
}
}
}
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();
}
nono00