結果
問題 | No.807 umg tours |
ユーザー | 双六 |
提出日時 | 2020-08-20 21:07:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,492 ms / 4,000 ms |
コード長 | 1,291 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 229,856 KB |
最終ジャッジ日時 | 2024-05-03 00:27:40 |
合計ジャッジ時間 | 16,464 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
64,204 KB |
testcase_01 | AC | 54 ms
65,456 KB |
testcase_02 | AC | 57 ms
69,132 KB |
testcase_03 | AC | 54 ms
67,420 KB |
testcase_04 | AC | 53 ms
64,052 KB |
testcase_05 | AC | 52 ms
66,024 KB |
testcase_06 | AC | 56 ms
68,452 KB |
testcase_07 | AC | 56 ms
67,532 KB |
testcase_08 | AC | 43 ms
55,176 KB |
testcase_09 | AC | 41 ms
55,352 KB |
testcase_10 | AC | 43 ms
56,024 KB |
testcase_11 | AC | 850 ms
153,992 KB |
testcase_12 | AC | 973 ms
166,512 KB |
testcase_13 | AC | 1,153 ms
185,224 KB |
testcase_14 | AC | 560 ms
126,056 KB |
testcase_15 | AC | 437 ms
117,256 KB |
testcase_16 | AC | 1,246 ms
189,616 KB |
testcase_17 | AC | 1,492 ms
228,428 KB |
testcase_18 | AC | 1,482 ms
229,856 KB |
testcase_19 | AC | 1,420 ms
227,856 KB |
testcase_20 | AC | 746 ms
184,264 KB |
testcase_21 | AC | 768 ms
185,492 KB |
testcase_22 | AC | 380 ms
117,916 KB |
testcase_23 | AC | 328 ms
108,764 KB |
testcase_24 | AC | 623 ms
202,468 KB |
testcase_25 | AC | 1,466 ms
225,988 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict from heapq import heappop, heappush con = 10 ** 9 + 7; 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.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 heappush(self.Q, (alt, v)) #処理内容 def main(): N, M = getlist() G = Graph() for i in range(M): a, b, w = getlist() a -= 1; b -= 1 G.add_edge(a, b, w) G.add_edge(b, a, w) G.add_edge(a, b + N, 0) G.add_edge(b, a + N, 0) G.add_edge(a + N, b + N, w) G.add_edge(b + N, a + N, w) D = Dijkstra(G, 0) print(0) for i in range(1, N): print(D.dist[i] + D.dist[i + N]) if __name__ == '__main__': main()