結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | 双六 |
提出日時 | 2020-07-23 17:28:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,734 ms / 5,000 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 87,376 KB |
実行使用メモリ | 94,324 KB |
最終ジャッジ日時 | 2023-09-05 22:26:50 |
合計ジャッジ時間 | 8,898 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
71,920 KB |
testcase_01 | AC | 92 ms
71,500 KB |
testcase_02 | AC | 92 ms
71,748 KB |
testcase_03 | AC | 91 ms
71,668 KB |
testcase_04 | AC | 127 ms
78,080 KB |
testcase_05 | AC | 125 ms
77,972 KB |
testcase_06 | AC | 136 ms
79,092 KB |
testcase_07 | AC | 138 ms
78,280 KB |
testcase_08 | AC | 139 ms
78,596 KB |
testcase_09 | AC | 117 ms
77,628 KB |
testcase_10 | AC | 145 ms
78,476 KB |
testcase_11 | AC | 149 ms
78,760 KB |
testcase_12 | AC | 148 ms
78,584 KB |
testcase_13 | AC | 129 ms
77,848 KB |
testcase_14 | AC | 150 ms
78,180 KB |
testcase_15 | AC | 140 ms
78,456 KB |
testcase_16 | AC | 116 ms
77,876 KB |
testcase_17 | AC | 148 ms
79,068 KB |
testcase_18 | AC | 135 ms
77,772 KB |
testcase_19 | AC | 116 ms
77,464 KB |
testcase_20 | AC | 117 ms
77,600 KB |
testcase_21 | AC | 138 ms
78,708 KB |
testcase_22 | AC | 142 ms
78,820 KB |
testcase_23 | AC | 130 ms
78,508 KB |
testcase_24 | AC | 121 ms
77,820 KB |
testcase_25 | AC | 126 ms
77,792 KB |
testcase_26 | AC | 131 ms
78,024 KB |
testcase_27 | AC | 103 ms
76,672 KB |
testcase_28 | AC | 3,734 ms
94,324 KB |
testcase_29 | AC | 97 ms
72,472 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict from heapq import heappop, heappush INF = float('inf') def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b, w): self.graph[a].append((b, w)) class Dijkstra(object): def __init__(self, graph, s): self.g = graph.graph self.dist = defaultdict(lambda: INF); self.dist[s] = 0 # self.prev = defaultdict(lambda: None) self.dic = defaultdict(lambda:[10 ** 3]) self.dic[s].append(s) self.Q = [] heappush(self.Q, (self.dist[s], s)) while self.Q: dist_u, u = heappop(self.Q) if self.dist[u] < dist_u: continue for v, w in self.g[u]: alt = dist_u + w if self.dist[v] > alt: self.dist[v] = alt # self.prev[v] = u self.dic[v] = self.dic[u] + [v] heappush(self.Q, (alt, v)) elif self.dist[v] == alt: if self.dic[u] + [v] < self.dic[v]: # self.prev[v] = u self.dic[v] = self.dic[u] + [v] heappush(self.Q, (alt, v)) def s_p(self, goal): path = [] node = goal while node is not None: path.append(node) node = self.prev[node] return path[::-1] #処理内容 def main(): N, M, s, g = getlist() G = Graph() for i in range(M): a, b, w = getlist() G.add_edge(a, b, w) G.add_edge(b, a, w) D = Dijkstra(G, s) ans = D.dic[g][1:] # print(D.dic[g]) print(*ans) if __name__ == '__main__': main()