結果
問題 |
No.3222 Let the World Forget Me
|
ユーザー |
![]() |
提出日時 | 2025-08-01 21:49:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 661 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 100,908 KB |
最終ジャッジ日時 | 2025-08-01 21:50:04 |
合計ジャッジ時間 | 11,210 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 24 |
ソースコード
n, m = map(int, input().split()) P = list(map(int, input().split())) node = [[] for _ in range(n)] for _ in range(n-1): u, v = [int(x)-1 for x in input().split()] node[u].append(v) node[v].append(u) C = list(map(int, input().split())) D = [-1] * n for i in range(len(C)): C[i] -= 1 D[C[i]] = 0 from collections import deque dq = deque(C) while dq: now = dq.popleft() for nxt in node[now]: if D[nxt] == -1: D[nxt] = D[now] + 1 dq.append(nxt) I = [i for i in range(n)] I.sort(key = lambda x: -P[x]) ans = 0 cnt = 0 for now in I: if D[now] > cnt: ans += P[now] cnt += 1 print(ans)