結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2023-08-31 10:52:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,465 ms / 4,000 ms |
コード長 | 1,393 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 169,240 KB |
最終ジャッジ日時 | 2025-01-03 04:30:54 |
合計ジャッジ時間 | 17,874 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
# ダイクストラ# ミラー頂点をN個作る、辺構造も同じ# ミラーへは有向辺コスト0# ダイクストラ1回で済ませられるかN, M = map(int, input().split())edges = [[] for i in range(N*2+1)]for i in range(M):a, b, c = map(int, input().split())# 現世界内edges[a].append((b, c))edges[b].append((a, c))# ミラー世界内edges[a+N].append((b+N, c))edges[b+N].append((a+N, c))# 現世界からミラー世界に有効辺コスト0edges[a].append((b+N, 0))edges[b].append((a+N, 0))from heapq import heappush, heappopINF = 10 ** 18def dijkstra(s, n, connect): #(始点, ノード数)distance = [INF] * nque = [(0, s)] #(distance, node)distance[s] = 0confirmed = [False] * n # ノードが確定済みかどうかwhile que:w,v = heappop(que)if distance[v]<w:continueconfirmed[v] = Truefor to, cost in connect[v]: # ノード v に隣接しているノードに対してif confirmed[to] == False and distance[v] + cost < distance[to]:distance[to] = distance[v] + costheappush(que, (distance[to], to))return distancedistance = dijkstra(1,N*2+1, edges)for i in range(1, N+1):if i == 1:ans = 0else:ans = distance[i]+distance[i+N]print(ans)