結果

問題 No.1477 Lamps on Graph
ユーザー 8nd5t8nd5t
提出日時 2021-04-16 20:43:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 107,792 KB
最終ジャッジ日時 2023-09-15 21:48:19
合計ジャッジ時間 10,966 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,204 KB
testcase_01 AC 96 ms
71,764 KB
testcase_02 AC 95 ms
71,492 KB
testcase_03 AC 96 ms
71,764 KB
testcase_04 AC 94 ms
71,576 KB
testcase_05 AC 95 ms
71,656 KB
testcase_06 AC 96 ms
71,620 KB
testcase_07 AC 96 ms
71,428 KB
testcase_08 AC 95 ms
71,332 KB
testcase_09 AC 95 ms
71,672 KB
testcase_10 AC 95 ms
71,208 KB
testcase_11 AC 95 ms
71,660 KB
testcase_12 AC 248 ms
86,976 KB
testcase_13 AC 231 ms
90,640 KB
testcase_14 AC 265 ms
88,980 KB
testcase_15 AC 202 ms
81,420 KB
testcase_16 AC 176 ms
83,580 KB
testcase_17 AC 171 ms
83,644 KB
testcase_18 AC 221 ms
99,352 KB
testcase_19 AC 219 ms
88,928 KB
testcase_20 AC 174 ms
80,680 KB
testcase_21 AC 203 ms
95,276 KB
testcase_22 AC 162 ms
79,136 KB
testcase_23 AC 220 ms
82,600 KB
testcase_24 AC 284 ms
95,584 KB
testcase_25 AC 189 ms
81,252 KB
testcase_26 AC 259 ms
95,108 KB
testcase_27 AC 206 ms
82,396 KB
testcase_28 AC 219 ms
86,608 KB
testcase_29 AC 210 ms
84,116 KB
testcase_30 AC 165 ms
90,640 KB
testcase_31 AC 171 ms
84,468 KB
testcase_32 AC 246 ms
107,792 KB
testcase_33 AC 242 ms
106,960 KB
testcase_34 AC 214 ms
106,264 KB
testcase_35 AC 317 ms
101,044 KB
testcase_36 AC 316 ms
98,608 KB
testcase_37 AC 305 ms
96,500 KB
testcase_38 AC 304 ms
96,660 KB
testcase_39 AC 319 ms
98,512 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([])
seen = [0]*n
res = []
for i,x in enumerate(ny):
    if x == 0:
        q.append(i)
        seen[i] = 1
while q:
    u = q.popleft()
    if b[u]: 
        res.append(u+1)
    for v in g[u]:
        if seen[v]: continue
        b[v] ^= b[u]
        ny[v] -= 1
        if ny[v] == 0:
            q.append(v)
            seen[v] = 1
print(len(res))
for x in res:
    print(x)
0