結果

問題 No.3393 Move on Highway
コンテスト
ユーザー mkawa2
提出日時 2025-11-28 22:54:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,838 ms / 3,000 ms
コード長 1,770 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 163,364 KB
最終ジャッジ日時 2025-11-28 22:55:36
合計ジャッジ時間 54,855 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

from heapq import *

n,m,c=LI()
to=[[] for _ in range(n)]
for _ in range(m):
    u,v,w=LI1()
    w+=1
    to[u].append((v,w+c))
    to[v].append((u,w+c))

d1=[inf]*n
d1[0]=0
hp=[(0,0)]
while hp:
    d,u=heappop(hp)
    if d!=d1[u]:continue
    for v,w in to[u]:
        nd=d+w
        if nd<d1[v]:
            d1[v]=nd
            heappush(hp,(nd,v))

d2=[inf]*n
d3=[inf]*n
d2[n-1]=d3[n-1]=0
hp=[(0,n-1,0)]
while hp:
    d,u,f=heappop(hp)
    if f:
        if d!=d3[u]:continue
        for v,w in to[u]:
            nd=d+w
            if nd<d3[v]:
                d3[v]=nd
                heappush(hp,(nd,v,f))
    else:
        if d != d2[u]: continue
        for v,w in to[u]:
            nd = d+w
            if nd < d2[v]:
                d2[v] = nd
                heappush(hp, (nd, v, f))
            nd = d+c
            if nd < d3[v]:
                d3[v] = nd
                heappush(hp, (nd, v, 1))
# print(d1)
# print(d2)
for u in range(1,n):
    ans=min(d1[-1],d1[u]+d3[u])
    print(ans)
0