結果
問題 |
No.3222 Let the World Forget Me
|
ユーザー |
![]() |
提出日時 | 2025-08-02 18:05:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,486 bytes |
コンパイル時間 | 735 ms |
コンパイル使用メモリ | 68,300 KB |
実行使用メモリ | 10,396 KB |
最終ジャッジ日時 | 2025-08-02 18:05:18 |
合計ジャッジ時間 | 4,265 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 25 WA * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:38:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 38 | for (int i = 0; i < n; i++) scanf("%d", ps + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | scanf("%d%d", &u, &v); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:46:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | for (int i = 0; i < m; i++) scanf("%d", cs + i), cs[i]--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3222.cc: No.3222 Let the World Forget Me - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ using ll = long long; using vi = vector<int>; using qi = queue<int>; using pii = pair<int,int>; /* global variables */ int ps[MAX_N], cs[MAX_N]; vi nbrs[MAX_N]; int ds[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", ps + i); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; nbrs[u].push_back(v); nbrs[v].push_back(u); } for (int i = 0; i < m; i++) scanf("%d", cs + i), cs[i]--; fill(ds, ds + n, -1); qi q; for (int i = 0; i < m; i++) ds[cs[i]] = 0, q.push(cs[i]); int maxd = 0; while (! q.empty()) { int u = q.front(); q.pop(); maxd = max(maxd, ds[u]); for (auto v: nbrs[u]) if (ds[v] < 0) ds[v] = ds[u] + 1, q.push(v); } //for (int i = 0; i < n; i++) printf(" %d", ds[i]); putchar('\n'); priority_queue<pii> pq; for (int u = 0; u < n; u++) if (ds[u] > 0 && nbrs[u].size() == 1) pq.push({ps[u], ds[u]}); ll sum = 0; for (int d = 0; ! pq.empty(); d++) { while (! pq.empty() && pq.top().second <= d) pq.pop(); if (pq.empty()) break; auto [pi, di] = pq.top(); pq.pop(); sum += pi; } printf("%lld\n", sum); return 0; }