結果

問題 No.1477 Lamps on Graph
ユーザー nephrologistnephrologist
提出日時 2021-04-16 20:33:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 116,104 KB
最終ジャッジ日時 2023-09-15 21:27:50
合計ジャッジ時間 10,764 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,556 KB
testcase_01 AC 94 ms
71,544 KB
testcase_02 AC 91 ms
71,500 KB
testcase_03 AC 91 ms
71,500 KB
testcase_04 AC 91 ms
71,872 KB
testcase_05 AC 91 ms
71,712 KB
testcase_06 AC 94 ms
71,860 KB
testcase_07 AC 91 ms
71,560 KB
testcase_08 AC 92 ms
71,784 KB
testcase_09 AC 92 ms
71,676 KB
testcase_10 AC 92 ms
71,652 KB
testcase_11 AC 92 ms
71,496 KB
testcase_12 AC 207 ms
89,368 KB
testcase_13 AC 204 ms
91,212 KB
testcase_14 AC 221 ms
91,044 KB
testcase_15 AC 171 ms
82,292 KB
testcase_16 AC 171 ms
86,340 KB
testcase_17 AC 165 ms
85,900 KB
testcase_18 AC 209 ms
104,716 KB
testcase_19 AC 197 ms
91,964 KB
testcase_20 AC 160 ms
80,936 KB
testcase_21 AC 204 ms
104,480 KB
testcase_22 AC 144 ms
79,412 KB
testcase_23 AC 182 ms
83,072 KB
testcase_24 AC 249 ms
97,564 KB
testcase_25 AC 168 ms
82,276 KB
testcase_26 AC 250 ms
98,480 KB
testcase_27 AC 181 ms
83,852 KB
testcase_28 AC 200 ms
89,312 KB
testcase_29 AC 193 ms
85,452 KB
testcase_30 AC 158 ms
95,180 KB
testcase_31 AC 168 ms
88,132 KB
testcase_32 AC 218 ms
116,104 KB
testcase_33 AC 211 ms
111,020 KB
testcase_34 AC 185 ms
101,156 KB
testcase_35 AC 290 ms
105,748 KB
testcase_36 AC 281 ms
102,884 KB
testcase_37 AC 263 ms
100,804 KB
testcase_38 AC 275 ms
100,752 KB
testcase_39 AC 278 ms
103,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
graph = [[] for _ in range(n)]
deg = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if A[b] > A[a]:
        graph[a].append(b)
        deg[b] += 1
    if A[a] > A[b]:
        graph[b].append(a)
        deg[a] += 1
k = int(input())
B = list(map(int, input().split()))


finished = [0] * n
lamp = [0] * n
for b in B:
    lamp[b - 1] = 1

start = deque()

for i in range(n):
    if deg[i] == 0:
        start.append(i)

ans = []

while start:
    v = start.popleft()
    finished[v] = 1
    if lamp[v] == 0:
        for u in graph[v]:
            deg[u] -= 1
            if deg[u] == 0:
                start.append(u)
    else:
        ans.append(v + 1)
        lamp[v] = 0
        finished[v] = 1
        for u in graph[v]:
            lamp[u] ^= 1
            deg[u] -= 1
            if deg[u] == 0:
                start.append(u)

if sum(lamp) > 0:
    print(-1)
    exit()

print(len(ans))
for a in ans:
    print(a)
0