結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2020-12-19 01:53:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,257 ms / 4,000 ms |
| コード長 | 875 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 81,956 KB |
| 実行使用メモリ | 153,440 KB |
| 最終ジャッジ日時 | 2024-09-21 09:49:01 |
| 合計ジャッジ時間 | 22,619 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
G[a].append((b, c))
G[b].append((a, c))
dist = [[inf]*2 for _ in range(N)]
dist[0][0] = 0
dist[0][1] = 0
que = []
heapq.heappush(que, (0, 0, 0)) # dist, node, used
heapq.heappush(que, (0, 0, 1))
while que:
ds, s, used = heapq.heappop(que)
if dist[s][used] < ds:
continue
for t, dt in G[s]:
if dist[t][used] > ds + dt:
dist[t][used] = ds + dt
heapq.heappush(que, (ds + dt, t, used))
if not used:
if dist[t][used + 1] > ds:
dist[t][used + 1] = ds
heapq.heappush(que, (ds, t, used + 1))
for d in dist:
print(sum(d))
tktk_snsn