結果
| 問題 |
No.1477 Lamps on Graph
|
| コンテスト | |
| ユーザー |
hiragn
|
| 提出日時 | 2022-11-29 22:49:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 486 ms / 2,000 ms |
| コード長 | 660 bytes |
| コンパイル時間 | 295 ms |
| コンパイル使用メモリ | 82,604 KB |
| 実行使用メモリ | 106,844 KB |
| 最終ジャッジ日時 | 2024-10-07 08:50:51 |
| 合計ジャッジ時間 | 11,831 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
g=[[] for _ in range(n)]
for _ in range(m):
u,v=map(int,input().split())
u-=1;v-=1
if a[u]<a[v]:
g[u].append(v)
if a[u]>a[v]:
g[v].append(u)
k=int(input())
b=list(map(int,input().split()))
memo=[0]*n
for i in b:
memo[i-1]=1
q=[(a[i-1],i-1) for i in b]
heapq.heapify(q)
ans=[]
while q:
num,now=heapq.heappop(q)
if memo[now]==0:
continue
ans.append(now)
memo[now]=0
for to in g[now]:
memo[to]=1-memo[to]
if memo[to]:
heapq.heappush(q,(a[to],to))
print(len(ans))
for i in ans:
print(i+1)
hiragn