結果
問題 | No.807 umg tours |
ユーザー | roaris |
提出日時 | 2019-08-04 19:11:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,160 ms / 4,000 ms |
コード長 | 1,778 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 183,028 KB |
最終ジャッジ日時 | 2024-07-08 14:11:22 |
合計ジャッジ時間 | 30,038 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
63,104 KB |
testcase_01 | AC | 54 ms
62,592 KB |
testcase_02 | AC | 61 ms
64,896 KB |
testcase_03 | AC | 57 ms
64,384 KB |
testcase_04 | AC | 52 ms
61,952 KB |
testcase_05 | AC | 55 ms
62,848 KB |
testcase_06 | AC | 56 ms
64,384 KB |
testcase_07 | AC | 57 ms
64,000 KB |
testcase_08 | AC | 43 ms
54,528 KB |
testcase_09 | AC | 43 ms
54,784 KB |
testcase_10 | AC | 42 ms
54,784 KB |
testcase_11 | AC | 1,235 ms
120,156 KB |
testcase_12 | AC | 1,829 ms
137,556 KB |
testcase_13 | AC | 2,088 ms
151,312 KB |
testcase_14 | AC | 972 ms
113,808 KB |
testcase_15 | AC | 715 ms
103,388 KB |
testcase_16 | AC | 2,012 ms
150,972 KB |
testcase_17 | AC | 2,906 ms
176,016 KB |
testcase_18 | AC | 2,786 ms
172,864 KB |
testcase_19 | AC | 2,602 ms
170,276 KB |
testcase_20 | AC | 1,667 ms
140,768 KB |
testcase_21 | AC | 1,591 ms
143,916 KB |
testcase_22 | AC | 667 ms
103,864 KB |
testcase_23 | AC | 541 ms
97,880 KB |
testcase_24 | AC | 1,623 ms
175,776 KB |
testcase_25 | AC | 3,160 ms
183,028 KB |
ソースコード
from heapq import heappush, heappop from collections import defaultdict import sys input = sys.stdin.readline def dijkstra(start): distance = [[10**18 for _ in range(2)] for _ in range(N+1)] distance[start][0] = 0 distance[start][1] = 0 priority_queue = [] for i in range(1, N+1): for j in range(2): heappush(priority_queue, (distance[i][j], i, j)) while len(priority_queue) > 0: current_dist, current_node, state = heappop(priority_queue) if distance[current_node][state] < current_dist: continue if state == 0: for next_node, w in adj_dict[current_node]: if distance[next_node][0] > distance[current_node][0] + w: distance[next_node][0] = distance[current_node][0] + w heappush(priority_queue, (distance[next_node][0], next_node, 0)) if distance[next_node][1] > distance[current_node][0]: distance[next_node][1] = distance[current_node][0] heappush(priority_queue, (distance[next_node][1], next_node, 1)) else: for next_node, w in adj_dict[current_node]: if distance[next_node][1] > distance[current_node][1] + w: distance[next_node][1] = distance[current_node][1] + w heappush(priority_queue, (distance[next_node][1], next_node, 1)) return distance N, M = map(int, input().split()) adj_dict = defaultdict(list) for _ in range(M): a_i, b_i, c_i = map(int, input().split()) adj_dict[a_i].append((b_i, c_i)) adj_dict[b_i].append((a_i, c_i)) distance = dijkstra(1) for i in range(1, N+1): ans = distance[i][0] + distance[i][1] print(ans)