結果

問題 No.160 最短経路のうち辞書順最小
ユーザー ああいいああいい
提出日時 2022-03-24 23:18:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 665 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 77,196 KB
最終ジャッジ日時 2024-04-21 08:13:45
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
52,480 KB
testcase_01 AC 50 ms
52,608 KB
testcase_02 AC 49 ms
52,856 KB
testcase_03 AC 51 ms
52,480 KB
testcase_04 AC 106 ms
76,544 KB
testcase_05 AC 115 ms
77,056 KB
testcase_06 AC 112 ms
77,196 KB
testcase_07 AC 89 ms
71,936 KB
testcase_08 AC 90 ms
71,936 KB
testcase_09 AC 91 ms
71,424 KB
testcase_10 AC 85 ms
71,720 KB
testcase_11 AC 88 ms
72,548 KB
testcase_12 AC 89 ms
72,480 KB
testcase_13 AC 85 ms
70,808 KB
testcase_14 AC 86 ms
71,512 KB
testcase_15 AC 83 ms
70,524 KB
testcase_16 AC 92 ms
72,832 KB
testcase_17 AC 85 ms
71,296 KB
testcase_18 AC 88 ms
71,808 KB
testcase_19 AC 88 ms
71,808 KB
testcase_20 AC 94 ms
73,272 KB
testcase_21 AC 85 ms
70,272 KB
testcase_22 AC 85 ms
71,040 KB
testcase_23 AC 88 ms
72,192 KB
testcase_24 AC 92 ms
73,216 KB
testcase_25 AC 86 ms
71,296 KB
testcase_26 AC 88 ms
70,656 KB
testcase_27 AC 57 ms
55,424 KB
testcase_28 AC 110 ms
77,184 KB
testcase_29 AC 54 ms
53,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,S,GG = 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))
import heapq
inf = 10 ** 8
dist = [inf] * N
dist[GG] = 0
q = [(0,GG)]
while q:
    d,now = heapq.heappop(q)
    if dist[now] < d:continue
    for v,c in G[now]:
        if dist[v] > d + c:
            dist[v] = d + c
            heapq.heappush(q,(d+c,v))
#print(dist)
ans = []
now = S
while now != GG:
    ans.append(now)
    _min = N + 5
    for v,c in G[now]:
        if dist[v] == dist[now] - c:
            if v < _min:
                _min = v
    now = _min
ans.append(GG)
print(*ans)
        
0