結果

問題 No.160 最短経路のうち辞書順最小
ユーザー yuyyuyuyuyyuyu
提出日時 2015-07-25 16:36:38
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 238 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 77,340 KB
実行使用メモリ 82,752 KB
最終ジャッジ日時 2023-09-24 12:24:37
合計ジャッジ時間 10,027 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
77,824 KB
testcase_01 AC 81 ms
77,976 KB
testcase_02 AC 79 ms
77,980 KB
testcase_03 AC 82 ms
77,968 KB
testcase_04 AC 238 ms
81,280 KB
testcase_05 AC 226 ms
81,852 KB
testcase_06 AC 236 ms
82,752 KB
testcase_07 AC 223 ms
81,544 KB
testcase_08 AC 221 ms
82,112 KB
testcase_09 AC 212 ms
81,676 KB
testcase_10 AC 214 ms
81,476 KB
testcase_11 AC 215 ms
81,428 KB
testcase_12 AC 209 ms
81,920 KB
testcase_13 AC 217 ms
81,948 KB
testcase_14 AC 214 ms
81,512 KB
testcase_15 AC 210 ms
81,472 KB
testcase_16 AC 219 ms
81,964 KB
testcase_17 AC 208 ms
81,632 KB
testcase_18 AC 207 ms
81,472 KB
testcase_19 AC 217 ms
81,604 KB
testcase_20 AC 222 ms
81,588 KB
testcase_21 AC 220 ms
81,552 KB
testcase_22 AC 221 ms
81,444 KB
testcase_23 AC 222 ms
81,888 KB
testcase_24 AC 227 ms
81,492 KB
testcase_25 AC 219 ms
81,524 KB
testcase_26 AC 219 ms
81,616 KB
testcase_27 AC 193 ms
81,084 KB
testcase_28 AC 223 ms
81,312 KB
testcase_29 AC 192 ms
80,864 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