結果
| 問題 |
No.1477 Lamps on Graph
|
| コンテスト | |
| ユーザー |
hiragn
|
| 提出日時 | 2022-11-29 21:22:57 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 925 bytes |
| コンパイル時間 | 135 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 29,560 KB |
| 最終ジャッジ日時 | 2024-10-07 08:18:24 |
| 合計ジャッジ時間 | 5,646 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 RE * 5 TLE * 1 -- * 27 |
ソースコード
from collections import defaultdict
import heapq
def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
adj = defaultdict(list)
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(lambda x: int(x) - 1, input().split()))
onoff = [(i in b) for i in range(n)]
hq = [(a[x], x) for x in b]
heapq.heapify(hq)
ans = []
while len(hq):
a, b = heapq.heappop(hq)
if not onoff[b]:
continue
ans.append(b + 1)
onoff[b] = False
for v in adj[b]:
onoff[v] = not onoff[v]
if onoff[v]:
heapq.heappush(hq, (a[v], v))
print(len(ans))
print(*ans, sep='\n')
if __name__ == "__main__":
main()
hiragn