結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
AEn
|
| 提出日時 | 2022-05-18 10:18:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 3,109 ms / 4,000 ms |
| コード長 | 913 bytes |
| コンパイル時間 | 428 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 149,676 KB |
| 最終ジャッジ日時 | 2025-03-30 10:34:05 |
| 合計ジャッジ時間 | 30,232 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from heapq import heappush, heappop
INF = float('inf')
N, M = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(M):
s, t, d = map(int, input().split())
s -= 1
t -= 1
adj[s].append((t, d))
adj[t].append((s, d))
def dijkstra(s, n):
dist = [[INF] * 2 for _ in range(N)]
hq = [(0, 0, s)]
dist[s][0] = 0
dist[s][1] = 0
while hq:
d, ticket, v = heappop(hq)
if d > dist[v][ticket]:
continue
for to, cost in adj[v]:
if dist[v][ticket] + cost < dist[to][ticket]:
dist[to][ticket] = d + cost
# prev[to] = v
heappush(hq, (dist[to][ticket], ticket, to))
if ticket == 0:
if dist[to][1] > d:
dist[to][1] = d
heappush(hq, (d, 1, to))
return dist
dis = dijkstra(0, N)
for a, b in dis:
print(a+b)
AEn