結果

問題 No.1477 Lamps on Graph
ユーザー NoaSaber
提出日時 2021-04-16 22:18:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 111,900 KB
最終ジャッジ日時 2024-07-03 02:15:12
合計ジャッジ時間 12,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=list(map(int,input().split()))
edge=[[] for i in range(N)]
score=[0]*N
for i in range(M):
    u,v=map(int,input().split())
    u-=1;v-=1
    if A[u]<A[v]:
        edge[u].append(v)
    if A[v]<A[u]:
        edge[v].append(u)
K=int(input())
B=list(map(int,input().split()))
q=[]
ans=0
for i in B:
    score[i-1]=1
    q.append((A[i-1],i-1))
import heapq
heapq.heapify(q)
ans_l=[]
while q:
    value,next=heapq.heappop(q)
    if score[next]%2==0:
        continue
    ans+=1
    ans_l.append(next)
    for i in edge[next]:
        score[i]=score[next]+1
        if score[i]%2==1:
            heapq.heappush(q,(A[i],i))
    score[next]=0
print(ans)
for i in ans_l:
    print(i+1)
0