結果
| 問題 | No.3393 Move on Highway |
| コンテスト | |
| ユーザー |
detteiuu
|
| 提出日時 | 2025-11-28 22:41:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,784 ms / 3,000 ms |
| コード長 | 1,446 bytes |
| コンパイル時間 | 471 ms |
| コンパイル使用メモリ | 82,252 KB |
| 実行使用メモリ | 180,416 KB |
| 最終ジャッジ日時 | 2025-11-28 22:42:08 |
| 合計ジャッジ時間 | 55,356 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
from heapq import heappush, heappop
N, M, C = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
u, v, w = map(int, input().split())
u, v = u-1, v-1
G[u].append((v, w))
G[v].append((u, w))
INF = 1<<60
def dijkstra(start):
dist = [INF]*N
dist[start] = 0
visited = [False]*N
que = [(0, start)]
while que:
d, now = heappop(que)
if visited[now]:
continue
visited[now] = True
for next, weight in G[now]:
if dist[now]+weight+C < dist[next]:
dist[next] = dist[now]+weight+C
heappush(que, (dist[next], next))
return dist
def dijkstra2(start):
dist = [[INF]*2 for _ in range(N)]
dist[start][0] = 0
visited = [[False]*2 for _ in range(N)]
que = [(0, (start, 0))]
while que:
d, now = heappop(que)
n, f = now
if visited[n][f]:
continue
visited[n][f] = True
for next, weight in G[n]:
if dist[n][f]+weight+C < dist[next][f]:
dist[next][f] = dist[n][f]+weight+C
heappush(que, (dist[next][f], (next, f)))
if f == 0 and dist[n][0]+C < dist[next][1]:
dist[next][1] = dist[n][0]+C
heappush(que, (dist[next][1], (next, 1)))
return dist
dist1 = dijkstra(0)
distN = dijkstra2(N-1)
for i in range(1, N):
print(min(dist1[-1], dist1[i]+distN[i][1]))
detteiuu