結果

問題 No.1477 Lamps on Graph
ユーザー titiatitia
提出日時 2021-04-16 21:58:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 671 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 41,140 KB
最終ジャッジ日時 2024-07-03 01:43:16
合計ジャッジ時間 13,480 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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]:
        DEGIN[to]-=1
        if DEGIN[to]==0:
            Q.append(to)

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



0