結果
問題 |
No.2711 Connecting Lights
|
ユーザー |
👑 |
提出日時 | 2024-03-31 15:29:08 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 730 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 67,900 KB |
最終ジャッジ日時 | 2024-09-30 20:45:31 |
合計ジャッジ時間 | 3,124 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 27 |
ソースコード
import heapq def solve(n, m, a, uvw): graph = [[] for _ in range(n)] for ui, vi, wi in uvw: graph[ui-1].append((vi - 1, wi)) pq = [(-a[0], 0)] mn = [10 ** 18] * n mn[0] = -a[0] while True: cost, node = heapq.heappop(pq) if node == n - 1: return -cost if mn[node] < cost: continue if cost < mn[node]: return "inf" for next_node, next_cost in graph[node]: if a[next_node] <= -cost - next_cost: continue a[next_node] = -cost + next_cost heapq.heappush(pq, (-a[next_node], next_node)) n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] uvw = [[int(x) for x in input().split()] for _ in range(m)] print(solve(n, m, a, uvw))