結果
| 問題 |
No.1477 Lamps on Graph
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-15 12:34:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 947 ms / 2,000 ms |
| コード長 | 655 bytes |
| コンパイル時間 | 102 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 40,860 KB |
| 最終ジャッジ日時 | 2024-09-22 04:30:49 |
| 合計ジャッジ時間 | 18,697 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)