結果

問題 No.160 最短経路のうち辞書順最小
ユーザー roiti46roiti46
提出日時 2015-03-01 23:54:32
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 243 ms / 5,000 ms
コード長 748 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 77,888 KB
実行使用メモリ 82,508 KB
最終ジャッジ日時 2023-09-06 06:02:40
合計ジャッジ時間 7,648 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
78,124 KB
testcase_01 AC 82 ms
78,192 KB
testcase_02 AC 81 ms
78,120 KB
testcase_03 AC 82 ms
77,892 KB
testcase_04 AC 243 ms
81,424 KB
testcase_05 AC 235 ms
82,004 KB
testcase_06 AC 241 ms
82,508 KB
testcase_07 AC 223 ms
81,544 KB
testcase_08 AC 224 ms
81,504 KB
testcase_09 AC 223 ms
81,616 KB
testcase_10 AC 224 ms
81,656 KB
testcase_11 AC 223 ms
81,552 KB
testcase_12 AC 221 ms
81,584 KB
testcase_13 AC 221 ms
81,644 KB
testcase_14 AC 222 ms
81,568 KB
testcase_15 AC 220 ms
81,936 KB
testcase_16 AC 225 ms
81,364 KB
testcase_17 AC 221 ms
81,564 KB
testcase_18 AC 221 ms
81,520 KB
testcase_19 AC 226 ms
81,604 KB
testcase_20 AC 225 ms
81,780 KB
testcase_21 AC 226 ms
81,688 KB
testcase_22 AC 219 ms
81,572 KB
testcase_23 AC 221 ms
81,580 KB
testcase_24 AC 226 ms
81,504 KB
testcase_25 AC 221 ms
81,596 KB
testcase_26 AC 221 ms
81,760 KB
testcase_27 AC 201 ms
81,008 KB
testcase_28 AC 223 ms
81,532 KB
testcase_29 AC 197 ms
80,500 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