結果

問題 No.1477 Lamps on Graph
ユーザー taiga000629taiga000629
提出日時 2021-04-16 22:28:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 1,801 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 113,432 KB
最終ジャッジ日時 2023-09-16 01:23:11
合計ジャッジ時間 11,991 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,228 KB
testcase_01 AC 69 ms
71,328 KB
testcase_02 AC 71 ms
71,416 KB
testcase_03 AC 69 ms
71,332 KB
testcase_04 AC 69 ms
71,348 KB
testcase_05 AC 69 ms
71,416 KB
testcase_06 AC 69 ms
71,324 KB
testcase_07 AC 69 ms
71,464 KB
testcase_08 AC 70 ms
71,524 KB
testcase_09 AC 68 ms
71,076 KB
testcase_10 AC 68 ms
71,228 KB
testcase_11 AC 69 ms
71,324 KB
testcase_12 AC 326 ms
91,268 KB
testcase_13 AC 302 ms
93,388 KB
testcase_14 AC 354 ms
92,692 KB
testcase_15 AC 240 ms
85,544 KB
testcase_16 AC 221 ms
85,884 KB
testcase_17 AC 220 ms
85,376 KB
testcase_18 AC 266 ms
100,868 KB
testcase_19 AC 294 ms
92,640 KB
testcase_20 AC 210 ms
82,832 KB
testcase_21 AC 252 ms
99,404 KB
testcase_22 AC 171 ms
80,040 KB
testcase_23 AC 263 ms
86,068 KB
testcase_24 AC 375 ms
100,160 KB
testcase_25 AC 233 ms
84,788 KB
testcase_26 AC 340 ms
99,420 KB
testcase_27 AC 260 ms
86,692 KB
testcase_28 AC 279 ms
89,408 KB
testcase_29 AC 276 ms
87,860 KB
testcase_30 AC 188 ms
89,456 KB
testcase_31 AC 215 ms
86,296 KB
testcase_32 AC 273 ms
113,432 KB
testcase_33 AC 268 ms
113,108 KB
testcase_34 AC 219 ms
103,348 KB
testcase_35 AC 417 ms
109,388 KB
testcase_36 AC 411 ms
107,592 KB
testcase_37 AC 383 ms
100,336 KB
testcase_38 AC 395 ms
102,792 KB
testcase_39 AC 416 ms
107,300 KB
権限があれば一括ダウンロードができます

ソースコード

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 ch(x):
    light[x]^=1
    ans.append(x)
    for nod in root[x]:
        light[nod]^=1

seen=[0]*(n+1)
ind=[0]*(n+1)
def tree_search(n,G,s,func1,func2,func3):
    #n...頂点の数
    #G...G[v]は頂点vから行ける頂点の配列
    #s...sが根
    #func1(now)...ある頂点に初めて訪れた時、その頂点のみでする処理。ない場合は0
    #func2(now,next)...nowからnextに移動する時に行う処理。ない場合は0
    #func3(now)...nowを去る時にする処理。なければ0

    ############## 計算量に注意 場合によっては配列生成をtree_search の外に出してもいい
    #seen=[0]*(n+1)
    #ind=[0]*(n+1)
    # record=[[] for i in range(n+1)] # 変数の情報記録
    ##############

    search=[s]
    while search:
        now=search[-1]
        if seen[now]==0 and func1!=0:func1(now)
        if memo[now]==1:pass
        seen[now]=1
        if len(G[now])>ind[now]:
            next=G[now][ind[now]]
            ind[now]+=1
            if seen[next]>0:continue
            if func2!=0:func2(now,next)
            search.append(next)
        else:
            if func3!=0:func3(now)
            search.pop()


def f(x):
    if light[x]==1:ch(x)
    memo[x]=1


for i in range(1,n+1):tree_search(n,rootr,i,0,0,f)
print(len(ans))
for x in ans:print(x)



0