結果

問題 No.160 最短経路のうち辞書順最小
ユーザー gigurururugigurururu
提出日時 2015-03-04 23:21:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 388 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 33,000 KB
最終ジャッジ日時 2023-09-06 12:56:32
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,140 KB
testcase_01 AC 16 ms
7,932 KB
testcase_02 AC 15 ms
8,004 KB
testcase_03 AC 17 ms
8,116 KB
testcase_04 AC 34 ms
9,840 KB
testcase_05 AC 60 ms
12,552 KB
testcase_06 AC 73 ms
13,088 KB
testcase_07 AC 28 ms
9,028 KB
testcase_08 AC 29 ms
9,084 KB
testcase_09 AC 25 ms
8,716 KB
testcase_10 AC 31 ms
8,960 KB
testcase_11 AC 31 ms
9,028 KB
testcase_12 AC 28 ms
8,952 KB
testcase_13 AC 28 ms
8,652 KB
testcase_14 AC 27 ms
8,724 KB
testcase_15 AC 26 ms
8,640 KB
testcase_16 AC 26 ms
8,652 KB
testcase_17 AC 29 ms
8,972 KB
testcase_18 AC 28 ms
8,680 KB
testcase_19 AC 29 ms
8,992 KB
testcase_20 AC 27 ms
9,052 KB
testcase_21 AC 27 ms
8,776 KB
testcase_22 AC 27 ms
8,696 KB
testcase_23 AC 29 ms
8,780 KB
testcase_24 AC 32 ms
9,160 KB
testcase_25 AC 27 ms
8,800 KB
testcase_26 AC 28 ms
9,024 KB
testcase_27 AC 19 ms
8,436 KB
testcase_28 AC 270 ms
33,000 KB
testcase_29 AC 18 ms
8,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N,M,S,G=map(int,input().split())
L=[[] for _ in range(N)]
for _ in range(M):
    a,b,c=map(int,input().split())
    L[a].append([b,c])
    L[b].append([a,c])
q=[[0,[S]],[1e9,[]]]
d={}
while True:
    e,n=heapq.heappop(q)
    t=n[-1]
    if t not in d:
        d[t]=True
        if t==G: break
        for j,i in L[t]: heapq.heappush(q,[i+e,n+[j]])
print(" ".join(map(str,n)))
0