結果

問題 No.1477 Lamps on Graph
ユーザー titia
提出日時 2021-04-16 21:35:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 737 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 325,072 KB
最終ジャッジ日時 2024-07-03 00:59:57
合計ジャッジ時間 9,817 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 13 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
E=[[] for i in range(N+1)]

for i in range(M):
    u,v=map(int,input().split())
    if A[u]>A[v]:
        E[v].append(u)
    elif A[v]>A[u]:
        E[u].append(v)

K=int(input())
B=list(map(int,input().split()))
LIGHT=[0]*(N+1)
for b in B:
    LIGHT[b]=1

DEGIN=[0]*(N+1)
for i in range(1,N+1):
    for k in E[i]:
        DEGIN[k]+=1

Q=[]
ANS=[]
for i in range(1,N+1):
    if DEGIN[i]==0:
        Q.append(i)
            
while Q:
    now=Q.pop()
    if LIGHT[now]==1:
        ANS.append(now)
        for to in E[now]:
            LIGHT[to]^=1
            
    for to in E[now]:    
        Q.append(to)

print(len(ANS))
print("\n".join(map(str,ANS)))
        
    



0