結果
| 問題 |
No.2431 Viral Hotel
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-28 18:25:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 71 ms / 2,000 ms |
| コード長 | 1,784 bytes |
| コンパイル時間 | 1,777 ms |
| コンパイル使用メモリ | 203,304 KB |
| 最終ジャッジ日時 | 2025-02-17 02:48:36 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~
ソースコード
#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;
}