結果
| 問題 | No.3393 Move on Highway |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-03 15:42:40 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 2,831 ms / 3,000 ms |
| コード長 | 1,047 bytes |
| 記録 | |
| コンパイル時間 | 306 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 161,808 KB |
| 最終ジャッジ日時 | 2025-12-03 15:43:44 |
| 合計ジャッジ時間 | 59,342 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
from heapq import heappop, heappush
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
cost_fr0 = [INF] * N
cost_fr0[0] = 0
hq = [(0, 0)]
while hq:
c, u = heappop(hq)
if cost_fr0[u] < c:
continue
for v, w in g[u]:
if cost_fr0[v] > c + w + C:
cost_fr0[v] = c + w + C
heappush(hq, (c + w + C, v))
cost_frN = [[INF] * N for _ in range(2)]
cost_frN[0][N - 1] = 0
hq = [(0, 0, N - 1)]
while hq:
c, t, u = heappop(hq)
if cost_frN[t][u] > c:
continue
for v, w in g[u]:
if t == 0 and cost_frN[1][v] > c + C:
cost_frN[1][v] = c + C
heappush(hq, (c + C, 1, v))
if cost_frN[t][v] > c + C + w:
cost_frN[t][v] = c + C + w
heappush(hq, (c + C + w, t, v))
ans = cost_fr0[N - 1]
for i in range(1, N - 1):
print(min(ans, cost_fr0[i] + cost_frN[1][i]))
print(ans)