結果

問題 No.160 最短経路のうち辞書順最小
ユーザー roiti46roiti46
提出日時 2015-03-01 23:58:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 3,644 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 8,980 KB
最終ジャッジ日時 2023-09-06 06:08:51
合計ジャッジ時間 94,090 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,016 KB
testcase_01 AC 11 ms
6,068 KB
testcase_02 AC 11 ms
6,016 KB
testcase_03 AC 12 ms
5,940 KB
testcase_04 AC 3,567 ms
7,812 KB
testcase_05 AC 3,613 ms
7,760 KB
testcase_06 AC 3,627 ms
7,832 KB
testcase_07 AC 3,586 ms
7,668 KB
testcase_08 AC 3,507 ms
7,596 KB
testcase_09 AC 3,509 ms
7,704 KB
testcase_10 AC 3,565 ms
7,712 KB
testcase_11 AC 3,513 ms
7,552 KB
testcase_12 AC 3,559 ms
7,704 KB
testcase_13 AC 3,539 ms
7,704 KB
testcase_14 AC 3,543 ms
7,676 KB
testcase_15 AC 3,566 ms
7,556 KB
testcase_16 AC 3,583 ms
7,616 KB
testcase_17 AC 3,621 ms
7,736 KB
testcase_18 AC 3,526 ms
7,604 KB
testcase_19 AC 3,642 ms
7,704 KB
testcase_20 AC 3,644 ms
7,788 KB
testcase_21 AC 3,625 ms
7,620 KB
testcase_22 AC 3,557 ms
7,556 KB
testcase_23 AC 3,516 ms
7,604 KB
testcase_24 AC 3,555 ms
7,828 KB
testcase_25 AC 3,501 ms
7,760 KB
testcase_26 AC 3,596 ms
7,672 KB
testcase_27 AC 3,512 ms
7,852 KB
testcase_28 AC 3,608 ms
8,980 KB
testcase_29 AC 3,588 ms
8,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy
inf = 10**9
def dfs(path,t):
    if path[-1] == G: return path
    spath = set(path)
    res = []
    for i in xrange(N):
        if i not in spath and t+cost[path[-1]][i]+mincost[i][G] <= time:
            res = dfs(path+[i],t+cost[path[-1]][i])
            if res: return res
    return []

N,M,S,G = map(int,raw_input().split())
cost = [[inf]*N for i in xrange(N)]
for i in xrange(N): cost[i][i] = 0
for loop in xrange(M):
    a,b,c = map(int,raw_input().split())
    cost[a][b] = cost[b][a] = c

mincost = copy.deepcopy(cost)
for k in xrange(N):
    for i in xrange(N):
        for j in xrange(N):
            mincost[i][j] = min(mincost[i][j], mincost[i][k]+mincost[k][j])

time = mincost[S][G]
print " ".join(map(str,dfs([S],0)))
0