結果

問題 No.1477 Lamps on Graph
ユーザー taiga000629
提出日時 2021-04-16 22:09:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 116,400 KB
最終ジャッジ日時 2024-07-03 01:59:35
合計ジャッジ時間 16,772 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
a=[-1]+list(map(int,input().split()))
root=[[] for i in range(n+1)]
rootr=[[] for i in range(n+1)]
import sys
sys.setrecursionlimit(10**9)
for i in range(m):
    v,u=map(int,input().split())
    if a[v]>a[u]:
        root[u].append(v)
        rootr[v].append(u)
    elif a[u]>a[v]:
        root[v].append(u)
        rootr[u].append(v)
memo=[-1]*(n+1)
light=[0]*(n+1)
ans=[]
k=int(input())
b=list(map(int,input().split()))
for x in b:light[x]=1
def f(x):
    if memo[x]!=-1:return memo[x]
    res=0
    for nod in rootr[x]:
        res+=f(nod)
    if light[x]^(res%2)==1:
        res+=1
        ans.append(x)
    memo[x]=res
    return res
def g(x):
    if len(root[x])==0:f(x)
    else:
        for nod in root[x]:g(nod)

for i in range(1,n+1):
    if memo[i]==-1:g(i)
print(len(ans))
for x in ans:
    print(x)




0