結果

問題 No.1477 Lamps on Graph
ユーザー hiragnhiragn
提出日時 2022-11-29 22:54:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 513 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 106,112 KB
最終ジャッジ日時 2024-04-16 13:35:46
合計ジャッジ時間 11,854 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
52,352 KB
testcase_01 AC 48 ms
52,480 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 44 ms
52,352 KB
testcase_04 AC 42 ms
52,480 KB
testcase_05 AC 44 ms
52,608 KB
testcase_06 AC 44 ms
52,480 KB
testcase_07 AC 44 ms
52,608 KB
testcase_08 AC 44 ms
52,608 KB
testcase_09 AC 44 ms
52,096 KB
testcase_10 AC 44 ms
52,608 KB
testcase_11 AC 43 ms
52,352 KB
testcase_12 AC 309 ms
86,392 KB
testcase_13 AC 339 ms
88,040 KB
testcase_14 AC 374 ms
88,656 KB
testcase_15 AC 224 ms
80,036 KB
testcase_16 AC 178 ms
82,560 KB
testcase_17 AC 202 ms
82,304 KB
testcase_18 AC 326 ms
95,232 KB
testcase_19 AC 268 ms
87,888 KB
testcase_20 AC 213 ms
79,964 KB
testcase_21 AC 298 ms
92,724 KB
testcase_22 AC 162 ms
78,336 KB
testcase_23 AC 232 ms
81,468 KB
testcase_24 AC 456 ms
92,996 KB
testcase_25 AC 207 ms
80,944 KB
testcase_26 AC 354 ms
92,748 KB
testcase_27 AC 215 ms
81,020 KB
testcase_28 AC 250 ms
84,480 KB
testcase_29 AC 249 ms
84,148 KB
testcase_30 AC 211 ms
87,792 KB
testcase_31 AC 202 ms
82,816 KB
testcase_32 AC 479 ms
106,112 KB
testcase_33 AC 436 ms
104,404 KB
testcase_34 AC 263 ms
100,852 KB
testcase_35 AC 513 ms
99,060 KB
testcase_36 AC 504 ms
97,388 KB
testcase_37 AC 336 ms
93,824 KB
testcase_38 AC 402 ms
94,184 KB
testcase_39 AC 441 ms
97,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))

adj = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if a[u] < a[v]:
        adj[u].append(v)
    if a[v] < a[u]:
        adj[v].append(u)

_ = int(input())
b = list(map(int, input().split()))
onoff = [0] * n
for i in b:
    onoff[i - 1] = 1

hq = [(a[i - 1], i - 1) for i in b]
heapq.heapify(hq)
ans = []
while hq:
    x, y = heapq.heappop(hq)
    if onoff[y] == 0:
        continue
    ans.append(y + 1)
    onoff[y] = False
    for v in adj[y]:
        onoff[v] = 1 - onoff[v]
        if onoff[v]:
            heapq.heappush(hq, (a[v], v))

print(len(ans))
print(*ans, sep='\n')
0