結果

問題 No.160 最短経路のうち辞書順最小
ユーザー DrDrpilotDrDrpilot
提出日時 2022-06-25 12:21:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 844 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 77,568 KB
最終ジャッジ日時 2024-04-26 18:33:02
合計ジャッジ時間 3,939 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 40 ms
52,864 KB
testcase_04 AC 92 ms
76,712 KB
testcase_05 AC 104 ms
77,312 KB
testcase_06 AC 108 ms
77,312 KB
testcase_07 AC 84 ms
73,088 KB
testcase_08 AC 82 ms
72,448 KB
testcase_09 AC 82 ms
71,808 KB
testcase_10 AC 81 ms
72,064 KB
testcase_11 AC 83 ms
73,344 KB
testcase_12 AC 84 ms
73,088 KB
testcase_13 AC 81 ms
71,552 KB
testcase_14 AC 80 ms
71,296 KB
testcase_15 AC 81 ms
71,296 KB
testcase_16 AC 87 ms
73,344 KB
testcase_17 AC 80 ms
71,296 KB
testcase_18 AC 83 ms
72,192 KB
testcase_19 AC 83 ms
72,576 KB
testcase_20 AC 86 ms
72,832 KB
testcase_21 AC 81 ms
71,424 KB
testcase_22 AC 81 ms
71,424 KB
testcase_23 AC 87 ms
73,600 KB
testcase_24 AC 87 ms
73,728 KB
testcase_25 AC 83 ms
72,448 KB
testcase_26 AC 81 ms
71,424 KB
testcase_27 AC 50 ms
55,168 KB
testcase_28 AC 103 ms
77,568 KB
testcase_29 AC 45 ms
53,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n,m,S,G=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    g[a].append((b,c))
    g[b].append((a,c))
dst=[10**18]*n
cfm=[False]*n
pre=[None]*n
q=[]
heapq.heappush(q,(0,G,-1))
while q:
    now_d,now_place,pre_place=heapq.heappop(q)
    if cfm[now_place]:
        continue
    pre[now_place]=pre_place
    cfm[now_place]=True
    dst[now_place]=now_d
    for to_place,cost in g[now_place]:
        if cfm[to_place]:
            continue
        if dst[to_place]<=now_d+cost:
            continue
        dst[to_place]=now_d+cost
        heapq.heappush(q,(now_d+cost,to_place,now_place))
now=S;ans=[]
while now!=G:
    tmp=10**18
    ans.append(now)
    for to,cost in g[now]:
        if dst[to]+cost==dst[now]:
            tmp=min(tmp,to)
    now=tmp
ans.append(G)
print(*ans)
0