結果

問題 No.160 最短経路のうち辞書順最小
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-12-30 18:57:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,100 KB
最終ジャッジ日時 2023-12-30 18:57:50
合計ジャッジ時間 3,612 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
61,540 KB
testcase_01 AC 47 ms
61,540 KB
testcase_02 AC 47 ms
61,540 KB
testcase_03 AC 47 ms
63,672 KB
testcase_04 AC 80 ms
77,968 KB
testcase_05 AC 87 ms
78,716 KB
testcase_06 AC 87 ms
79,100 KB
testcase_07 AC 68 ms
73,676 KB
testcase_08 AC 75 ms
73,656 KB
testcase_09 AC 69 ms
73,664 KB
testcase_10 AC 66 ms
71,568 KB
testcase_11 AC 67 ms
73,516 KB
testcase_12 AC 68 ms
73,644 KB
testcase_13 AC 66 ms
71,568 KB
testcase_14 AC 65 ms
71,568 KB
testcase_15 AC 64 ms
71,568 KB
testcase_16 AC 71 ms
73,652 KB
testcase_17 AC 66 ms
71,568 KB
testcase_18 AC 65 ms
71,440 KB
testcase_19 AC 70 ms
73,656 KB
testcase_20 AC 73 ms
73,656 KB
testcase_21 AC 65 ms
71,568 KB
testcase_22 AC 63 ms
71,440 KB
testcase_23 AC 73 ms
73,512 KB
testcase_24 AC 72 ms
73,904 KB
testcase_25 AC 67 ms
71,568 KB
testcase_26 AC 69 ms
73,532 KB
testcase_27 AC 57 ms
66,884 KB
testcase_28 AC 86 ms
78,972 KB
testcase_29 AC 59 ms
69,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math,time,random
input = sys.stdin.readline

INF = (1<<60)
N,M,S,G = map(int,input().split())
e = [[] for _ in range(N)]
dist = defaultdict(lambda:defaultdict(lambda:INF))
for _ in range(M):
    u,v,c = map(int,input().split())
    e[u].append((v,c))
    e[v].append((u,c))
    dist[u][v] = c
    dist[v][u] = c
def dijkstra(s,e):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []

    heappush(h,(0,s))
    while h:
        nw,v = heappop(h)
        if dist[v]!=nw:
            continue
        for iv,ic in e[v]:
            nc = ic + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,(nc,iv))
    return dist


D = dijkstra(G,e)

X = [S]
while X[-1]!=G:
    x = X[-1]
    for i in range(N):
        if D[i]+dist[i][x] == D[x]:
            X.append(i)
            break
print(*X)
0