結果

問題 No.1477 Lamps on Graph
ユーザー hiragnhiragn
提出日時 2022-11-29 22:01:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 778 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 97,280 KB
最終ジャッジ日時 2024-10-07 08:34:56
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
from sys import stdin

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

adj = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, stdin.readline().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(lambda x: int(x) - 1, stdin.readline().split()))
onoff = [(i in b) for i in range(n)]

hq = [(a[i], i) 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