結果

問題 No.1477 Lamps on Graph
ユーザー taiga000629taiga000629
提出日時 2021-04-16 22:09:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 845 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 117,244 KB
最終ジャッジ日時 2023-09-16 00:53:42
合計ジャッジ時間 16,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,452 KB
testcase_01 AC 68 ms
71,424 KB
testcase_02 AC 68 ms
71,300 KB
testcase_03 WA -
testcase_04 AC 72 ms
71,264 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 70 ms
71,372 KB
testcase_08 AC 69 ms
71,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 71 ms
71,444 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 244 ms
111,528 KB
testcase_34 AC 206 ms
107,868 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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