結果

問題 No.1477 Lamps on Graph
ユーザー 8nd5t8nd5t
提出日時 2021-04-16 20:48:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 107,404 KB
最終ジャッジ日時 2023-09-15 22:01:06
合計ジャッジ時間 10,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,240 KB
testcase_01 AC 96 ms
71,520 KB
testcase_02 AC 96 ms
71,444 KB
testcase_03 AC 95 ms
71,448 KB
testcase_04 AC 95 ms
71,232 KB
testcase_05 AC 95 ms
71,676 KB
testcase_06 AC 93 ms
71,564 KB
testcase_07 AC 95 ms
71,360 KB
testcase_08 AC 95 ms
71,828 KB
testcase_09 AC 93 ms
71,704 KB
testcase_10 AC 95 ms
71,636 KB
testcase_11 AC 95 ms
71,368 KB
testcase_12 AC 235 ms
86,660 KB
testcase_13 AC 222 ms
89,936 KB
testcase_14 AC 256 ms
88,620 KB
testcase_15 AC 194 ms
81,364 KB
testcase_16 AC 171 ms
83,912 KB
testcase_17 AC 168 ms
83,504 KB
testcase_18 AC 217 ms
98,532 KB
testcase_19 AC 215 ms
88,308 KB
testcase_20 AC 172 ms
80,552 KB
testcase_21 AC 201 ms
94,888 KB
testcase_22 AC 158 ms
79,396 KB
testcase_23 AC 209 ms
82,272 KB
testcase_24 AC 282 ms
94,772 KB
testcase_25 AC 186 ms
80,948 KB
testcase_26 AC 253 ms
94,480 KB
testcase_27 AC 204 ms
82,256 KB
testcase_28 AC 216 ms
86,492 KB
testcase_29 AC 207 ms
83,780 KB
testcase_30 AC 161 ms
90,504 KB
testcase_31 AC 170 ms
84,376 KB
testcase_32 AC 240 ms
107,404 KB
testcase_33 AC 235 ms
106,324 KB
testcase_34 AC 211 ms
105,732 KB
testcase_35 AC 299 ms
100,020 KB
testcase_36 AC 299 ms
97,852 KB
testcase_37 AC 294 ms
96,508 KB
testcase_38 AC 287 ms
96,428 KB
testcase_39 AC 293 ms
97,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right 
from heapq import heappop,heappush,heapify
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))
def inps(): return sys.stdin.readline()
def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])
def err(x): print(x); exit()

n,m = inpl()
a = inpl()
g = [[] for _ in range(n)]
ny = [0]*n
for _ in range(m):
    u,v = inpl_1()
    if a[u] == a[v]: continue
    if a[u] > a[v]: u,v = v,u
    g[u].append(v)
    ny[v] += 1
k = inp()
b = [0]*n
for x in inpl():
    b[x-1] = 1
q = deque([])
res = []
for i,x in enumerate(ny):
    if x == 0:
        q.append(i)
while q:
    u = q.popleft()
    if b[u]: 
        res.append(u+1)
    for v in g[u]:
        b[v] ^= b[u]
        ny[v] -= 1
        if ny[v] == 0:
            q.append(v)
print(len(res))
for x in res:
    print(x)
0