結果
| 問題 | No.3393 Move on Highway |
| コンテスト | |
| ユーザー |
yt142857
|
| 提出日時 | 2025-11-21 23:09:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,606 ms / 3,000 ms |
| コード長 | 1,187 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,836 KB |
| 実行使用メモリ | 235,764 KB |
| 最終ジャッジ日時 | 2025-11-28 20:59:36 |
| 合計ジャッジ時間 | 53,808 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
import heapq
n,m,k = map(int,input().split())
graph = {}
for i in range(1,n+1):
graph[i] = []
edgs = []
for i in range(m):
a,b,c = map(int,input().split())
edgs.append((a,b,c))
graph[a].append((b,c+k))
graph[b].append((a,c+k))
kakutei = [False]*(n+1)
heap = [(0,1)]
cur = [float('inf')]*(n+1)
cur[1] = 0
while heap:
n_dis,node = heapq.heappop(heap)
if kakutei[node]:
continue
kakutei[node] = True
for nei,n_dis in graph[node]:
if cur[node]+n_dis < cur[nei]:
heapq.heappush(heap,(cur[node]+n_dis,nei))
cur[nei] = cur[node]+n_dis
mae_cur = cur[:]
for i in range(n+1,2*n+1):
graph[i] = []
for a,b,c in edgs:
graph[a].append((b+n,k))
graph[b].append((a+n,k))
graph[a+n].append((b+n,c+k))
graph[b+n].append((a+n,c+k))
n *= 2
kakutei = [False]*(n+1)
heap = [(0,n//2)]
cur = [float('inf')]*(n+1)
cur[n//2] = 0
while heap:
n_dis,node = heapq.heappop(heap)
if kakutei[node]:
continue
kakutei[node] = True
for nei,n_dis in graph[node]:
if cur[node]+n_dis < cur[nei]:
heapq.heappush(heap,(cur[node]+n_dis,nei))
cur[nei] = cur[node]+n_dis
n = n//2
for i in range(2,n+1):
print(min(mae_cur[i]+cur[i+n],mae_cur[-1]))
yt142857