結果
問題 |
No.1477 Lamps on Graph
|
ユーザー |
![]() |
提出日時 | 2022-11-29 22:54:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 106,056 KB |
最終ジャッジ日時 | 2024-10-07 08:52:30 |
合計ジャッジ時間 | 10,306 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
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')