結果
問題 |
No.160 最短経路のうち辞書順最小
|
ユーザー |
|
提出日時 | 2015-03-01 23:46:16 |
言語 | PyPy2 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 831 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 76,964 KB |
実行使用メモリ | 90,152 KB |
最終ジャッジ日時 | 2024-06-24 00:42:25 |
合計ジャッジ時間 | 7,702 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 3 TLE * 1 -- * 22 |
ソースコード
inf = 10**9 def dijkstra(s): used = [False]*N d = [inf]*N d[s] = 0 while 1: v = -1 for u in xrange(N): if not used[u] and (v == -1 or d[u] < d[v]): v = u if v == -1: break used[v] = True for u in xrange(N): d[u] = min(d[u], d[v]+cost[v][u]) return d[G] 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[i][path[-1]] <= time: res = dfs(path+[i],t+cost[i][path[-1]]) if res: return res return [] N,M,S,G = map(int,raw_input().split()) cost = [[inf]*N for i in xrange(N)] for loop in xrange(M): a,b,c = map(int,raw_input().split()) cost[a][b] = cost[b][a] = c time = dijkstra(S) print " ".join(map(str,dfs([S],0)))