結果

問題 No.160 最短経路のうち辞書順最小
ユーザー titiatitia
提出日時 2022-03-30 01:18:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-04-26 10:09:09
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,008 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 53 ms
11,520 KB
testcase_05 AC 73 ms
12,160 KB
testcase_06 AC 91 ms
13,184 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 39 ms
11,264 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 41 ms
11,136 KB
testcase_20 AC 42 ms
11,264 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 33 ms
10,880 KB
testcase_28 WA -
testcase_29 AC 32 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush

N,M,S,G=map(int,input().split())
E=[[] for i in range(N+1)]

for i in range(M):
    a,b,c=map(int,input().split())
    E[a].append((b,c))
    E[b].append((a,c))
    
D=[1<<30]*(N+1)
FROM=[-1]*(N+1)
D[S]=0
Q=[]
Q.append((0,S))

while Q:
    time,now=heappop(Q)

    if D[now]!=time:
        continue

    for to,cost in E[now]:
        if D[to]>time+cost:
            D[to]=time+cost
            heappush(Q,(D[to],to))
            FROM[to]=now
        elif D[to]==time+cost:
            FROM[to]=min(FROM[to],now)
        
now=G
ANS=[G]
while now!=S:
    now=FROM[now]
    ANS.append(now)

print(*ANS[::-1])
0