Submission #30845182


Source Code Expand

import heapq
n, m = map(int, input().split())
e = [[] for i in range(n)] # グラフの隣接リスト
for i in range(m):
    u, v, c = map(int, input().split())
    e[u].append([v, c]) # 行先の頂点とコストを一緒に持つ
dist = [10 ** 18] * n # 各頂点への最短距離 (確定または暫定値)
dist[0] = 0
q = [] # 最短距離確定済み頂点に隣接した頂点の集合
heapq.heappush(q, [0, 0])
while len(q) != 0: # 未確定の頂点が残っている間繰り返す
    d, v = heapq.heappop(q) # 暫定距離最小の頂点とその距離を取り出し削除
    if dist[v] != d:
        continue
    for u, c in e[v]: # 最短距離の暫定値を更新し,優先度付きキューに追加
        if dist[u] > d + c:
            dist[u] = d + c
            heapq.heappush(q, [d + c, u])
print(dist[n - 1])

Submission Info

Submission Time
Task D - 単一始点最短経路問題
User Pro_ktmr
Language PyPy3 (7.3.0)
Score 100
Code Size 857 Byte
Status AC
Exec Time 282 ms
Memory 88736 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 18
Set Name Test Cases
Sample sample
All sample, dijkstra_complete, dijkstra_grid_0, dijkstra_grid_1, dijkstra_grid_2, dijkstra_grid_3, dijkstra_grid_4, dijkstra_path_0, dijkstra_path_1, dijkstra_path_2, dijkstra_path_3, dijkstra_path_4, dijkstra_random_0, dijkstra_random_1, dijkstra_random_2, dijkstra_random_3, dijkstra_random_4, sample
Case Name Status Exec Time Memory
dijkstra_complete AC 161 ms 78116 KiB
dijkstra_grid_0 AC 196 ms 80700 KiB
dijkstra_grid_1 AC 188 ms 79816 KiB
dijkstra_grid_2 AC 197 ms 80160 KiB
dijkstra_grid_3 AC 181 ms 79788 KiB
dijkstra_grid_4 AC 201 ms 80768 KiB
dijkstra_path_0 AC 265 ms 88736 KiB
dijkstra_path_1 AC 272 ms 88668 KiB
dijkstra_path_2 AC 266 ms 88612 KiB
dijkstra_path_3 AC 263 ms 88676 KiB
dijkstra_path_4 AC 282 ms 88640 KiB
dijkstra_random_0 AC 239 ms 84032 KiB
dijkstra_random_1 AC 240 ms 83848 KiB
dijkstra_random_2 AC 247 ms 84004 KiB
dijkstra_random_3 AC 245 ms 83688 KiB
dijkstra_random_4 AC 238 ms 84196 KiB
sample AC 54 ms 62204 KiB