結果
| 問題 |
No.3222 Let the World Forget Me
|
| ユーザー |
timi
|
| 提出日時 | 2025-08-03 13:36:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 802 bytes |
| コンパイル時間 | 288 ms |
| コンパイル使用メモリ | 82,616 KB |
| 実行使用メモリ | 99,664 KB |
| 最終ジャッジ日時 | 2025-08-03 13:36:57 |
| 合計ジャッジ時間 | 8,651 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 RE * 30 |
ソースコード
N,M=map(int, input().split())
A=list(map(int, input().split()))
D=[[] for i in range(N)]
G=[0]*N
from collections import deque
d=deque()
for i in range(N-1):
u,v=map(int, input().split())
u-=1;v-=1
D[u].append(v);D[v].append(u)
G[u]+=1;G[v]+=1
C=list(map(int, input().split()))
P=[0]*N
for c in C:
d.append(c-1)
P[c-1]=1
import heapq
E=[]
for i in range(N):
if G[i]==1 and P[i]==0:
heapq.heappush(E,(-A[i],i))
ans=0
for i in range(N):
while E:
x,y=heapq.heappop(E)
if P[y]==0:
ans-=x
for nex in D[x]:
G[nex]-=1
if G[nex]==1 and P[nex]==0:
heapq.heappush(E,(-A[nex],nex))
break
nd=deque()
while d:
now=d.popleft()
for nex in D[now]:
if P[nex]==0:
P[nex]=1
nd.append(nex)
d=nd
print(ans)
timi