結果
| 問題 |
No.3222 Let the World Forget Me
|
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2025-08-01 22:02:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 488 ms / 2,000 ms |
| コード長 | 1,054 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 82,588 KB |
| 実行使用メモリ | 117,212 KB |
| 最終ジャッジ日時 | 2025-08-01 22:02:31 |
| 合計ジャッジ時間 | 11,613 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
N,M=map(int,input().split())
P=list(map(int,input().split()))
for i in range(N):
P[i]=-P[i]
G=[set() for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].add(b-1)
G[b-1].add(a-1)
C=list(map(int,input().split()))
L=[]
for x in C:
L.append(x-1)
result=0
used=[False]*N
winned=[False]*N
from heapq import heappush,heappop
S=[]
for i in range(N):
x=P[i]
if len(G[i])==1:
heappush(S,x*10**6+i)
while True:
L2=[]
if len(L)==0:
break
for e in L:
if used[e]==True:
continue
if winned[e]==True:
continue
used[e]=True
for y in G[e]:
if used[y]==True or winned[y]==True:
continue
L2.append(y)
L=L2[:]
L2=[]
while S:
w=heappop(S)
t=w//(10**6)
pos=w%(10**6)
if used[pos]==True:
continue
if winned[pos]==True:
continue
winned[pos]=True
result-=t
a=-1
for y in G[pos]:
a=y
G[pos].remove(a)
G[a].remove(pos)
if len(G[a])==1:
x=P[a]
heappush(S,x*10**6+a)
break
print(result)
ゼット