結果

問題 No.160 最短経路のうち辞書順最小
ユーザー nebukuro09nebukuro09
提出日時 2016-09-28 17:40:52
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 2,974 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 76,428 KB
実行使用メモリ 95,124 KB
最終ジャッジ日時 2024-05-01 06:21:52
合計ジャッジ時間 7,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,292 KB
testcase_01 AC 75 ms
75,572 KB
testcase_02 AC 75 ms
75,552 KB
testcase_03 AC 76 ms
75,684 KB
testcase_04 AC 142 ms
79,636 KB
testcase_05 AC 126 ms
79,512 KB
testcase_06 AC 128 ms
79,528 KB
testcase_07 AC 134 ms
79,496 KB
testcase_08 AC 128 ms
79,764 KB
testcase_09 AC 114 ms
79,392 KB
testcase_10 AC 135 ms
79,636 KB
testcase_11 AC 141 ms
79,776 KB
testcase_12 AC 130 ms
79,620 KB
testcase_13 AC 121 ms
79,652 KB
testcase_14 AC 138 ms
79,924 KB
testcase_15 AC 139 ms
79,528 KB
testcase_16 AC 110 ms
79,292 KB
testcase_17 AC 138 ms
79,380 KB
testcase_18 AC 124 ms
79,636 KB
testcase_19 AC 107 ms
78,600 KB
testcase_20 AC 113 ms
79,376 KB
testcase_21 AC 135 ms
79,644 KB
testcase_22 AC 136 ms
79,400 KB
testcase_23 AC 129 ms
79,752 KB
testcase_24 AC 118 ms
79,752 KB
testcase_25 AC 124 ms
79,776 KB
testcase_26 AC 123 ms
79,804 KB
testcase_27 AC 86 ms
77,984 KB
testcase_28 AC 2,974 ms
95,124 KB
testcase_29 AC 79 ms
77,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, M, S, G = map(int, raw_input().split())
rinsetsu = [[] for i in xrange(N)]
for _ in xrange(M):
    a, b, c = map(int, raw_input().split())
    rinsetsu[a].append((b, c))
    rinsetsu[b].append((a, c))

def dijkstra():
    dist = [(float('inf'), []) for i in xrange(N)]
    dist[S] = (0, [S])
    q = []

    for n, c in rinsetsu[S]:
        heapq.heappush(q, (c, n))
        dist[n] = (c, [S, n])

    while len(q) != 0:
        c, n = heapq.heappop(q)
        if c > dist[n][0]:
            continue
        for nn, nc in rinsetsu[n]:
            alt = dist[n][0] + nc
            if dist[nn][0] > alt or (dist[nn][0] == alt and dist[n][1]+[nn] < dist[nn][1]):
                dist[nn] = (alt, dist[n][1]+[nn])
                heapq.heappush(q, (alt, nn))
                
    return dist

print ' '.join(map(str, dijkstra()[G][1]))
0