結果

問題 No.1477 Lamps on Graph
ユーザー hiragnhiragn
提出日時 2022-11-29 22:40:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 772 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 97,448 KB
最終ジャッジ日時 2024-04-16 13:32:35
合計ジャッジ時間 10,784 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
59,264 KB
testcase_01 AC 48 ms
54,016 KB
testcase_02 AC 50 ms
54,144 KB
testcase_03 AC 49 ms
54,016 KB
testcase_04 AC 48 ms
54,016 KB
testcase_05 AC 48 ms
54,272 KB
testcase_06 AC 48 ms
54,272 KB
testcase_07 AC 50 ms
54,016 KB
testcase_08 AC 50 ms
54,144 KB
testcase_09 AC 48 ms
54,528 KB
testcase_10 AC 48 ms
54,272 KB
testcase_11 AC 48 ms
54,272 KB
testcase_12 AC 1,077 ms
94,660 KB
testcase_13 AC 1,575 ms
94,356 KB
testcase_14 AC 1,590 ms
97,448 KB
testcase_15 AC 267 ms
83,720 KB
testcase_16 AC 373 ms
83,328 KB
testcase_17 AC 504 ms
83,712 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
import collections

input = sys.stdin.readline

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

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

_ = int(input())
b = list(map(int, input().split()))
onoff = [(i + 1 in b) for i in range(n)]

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

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