結果
問題 | No.807 umg tours |
ユーザー | roaris |
提出日時 | 2019-08-04 19:25:45 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,778 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 81,888 KB |
実行使用メモリ | 117,040 KB |
最終ジャッジ日時 | 2024-07-16 00:27:13 |
合計ジャッジ時間 | 6,425 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
ソースコード
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 = [] heappush(priority_queue, (distance[start][0], start)) heappush(priority_queue, (distance[start][1], start)) 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)