結果
| 問題 | No.1477 Lamps on Graph | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-04-16 22:49:16 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 765 bytes | 
| コンパイル時間 | 208 ms | 
| コンパイル使用メモリ | 82,168 KB | 
| 実行使用メモリ | 112,676 KB | 
| 最終ジャッジ日時 | 2024-07-03 03:09:26 | 
| 合計ジャッジ時間 | 15,904 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 5 WA * 33 | 
ソースコード
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=[]
inf=float("inf")
while q:
    value,next=heapq.heappop(q)
    if score[next]==-1:
        continue
    if value!=-1:
        ans+=1
        ans_l.append(next)
    for i in edge[next]:
        if score[i]==-1:
            continue
        score[i]=score[next]+1
        heapq.heappush(q,(-1,i))
    score[next]=-1
print(ans)
for i in ans_l:
    print(i+1)
            
            
            
        