Submission #55346606


Source Code Expand

from heapq import heappush, heappop
import sys

input = sys.stdin.readline


def dijkstra(G, s):
    INF = 10**18
    dist = [INF] * len(G)
    dist[s] = 0
    pq = [(0, s)]
    while pq:
        d, v = heappop(pq)
        if d > dist[v]:
            continue
        for u, weight in G[v]:
            nd = d + weight
            if dist[u] > nd:
                dist[u] = nd
                heappush(pq, (nd, u))
    return dist


N, M = map(int, input().split())
A = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(M):
    U, V, B = map(int, input().split())
    U -= 1
    V -= 1
    G[U].append((V, B + A[V]))
    G[V].append((U, B + A[U]))
dist = dijkstra(G, 0)
for i in range(N):
    dist[i] += A[0]
print(*dist[1:])

Submission Info

Submission Time
Task D - Shortest Path 3
User sotanishy
Language Python (PyPy 3.10-v7.3.12)
Score 425
Code Size 786 Byte
Status AC
Exec Time 444 ms
Memory 144132 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 41
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random-small_01.txt, 01_random-small_02.txt, 01_random-small_03.txt, 01_random-small_04.txt, 01_random-small_05.txt, 01_random-small_06.txt, 01_random-small_07.txt, 01_random-small_08.txt, 01_random-small_09.txt, 01_random-small_10.txt, 01_random-small_11.txt, 01_random-small_12.txt, 01_random-small_13.txt, 01_random-small_14.txt, 01_random-small_15.txt, 02_random-large_01.txt, 02_random-large_02.txt, 02_random-large_03.txt, 02_random-large_04.txt, 02_random-large_05.txt, 02_random-large_06.txt, 02_random-large_07.txt, 02_random-large_08.txt, 02_random-large_09.txt, 02_random-large_10.txt, 02_random-large_11.txt, 02_random-large_12.txt, 02_random-large_13.txt, 02_random-large_14.txt, 02_random-large_15.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 57 ms 76384 KiB
00_sample_02.txt AC 58 ms 76364 KiB
00_sample_03.txt AC 57 ms 76784 KiB
01_random-small_01.txt AC 75 ms 81620 KiB
01_random-small_02.txt AC 77 ms 82224 KiB
01_random-small_03.txt AC 74 ms 82036 KiB
01_random-small_04.txt AC 78 ms 81928 KiB
01_random-small_05.txt AC 134 ms 100364 KiB
01_random-small_06.txt AC 103 ms 86624 KiB
01_random-small_07.txt AC 84 ms 85024 KiB
01_random-small_08.txt AC 128 ms 95720 KiB
01_random-small_09.txt AC 61 ms 80344 KiB
01_random-small_10.txt AC 106 ms 88056 KiB
01_random-small_11.txt AC 87 ms 84576 KiB
01_random-small_12.txt AC 103 ms 86328 KiB
01_random-small_13.txt AC 137 ms 101332 KiB
01_random-small_14.txt AC 80 ms 82768 KiB
01_random-small_15.txt AC 98 ms 87092 KiB
02_random-large_01.txt AC 257 ms 110892 KiB
02_random-large_02.txt AC 444 ms 132660 KiB
02_random-large_03.txt AC 109 ms 85772 KiB
02_random-large_04.txt AC 435 ms 132804 KiB
02_random-large_05.txt AC 304 ms 111732 KiB
02_random-large_06.txt AC 423 ms 132580 KiB
02_random-large_07.txt AC 365 ms 120948 KiB
02_random-large_08.txt AC 444 ms 133064 KiB
02_random-large_09.txt AC 247 ms 105576 KiB
02_random-large_10.txt AC 443 ms 132416 KiB
02_random-large_11.txt AC 416 ms 130376 KiB
02_random-large_12.txt AC 436 ms 132856 KiB
02_random-large_13.txt AC 401 ms 126680 KiB
02_random-large_14.txt AC 422 ms 132748 KiB
02_random-large_15.txt AC 246 ms 104608 KiB
03_handmade_01.txt AC 289 ms 127776 KiB
03_handmade_02.txt AC 360 ms 127616 KiB
03_handmade_03.txt AC 425 ms 144132 KiB
03_handmade_04.txt AC 139 ms 101256 KiB
03_handmade_05.txt AC 355 ms 123552 KiB
03_handmade_06.txt AC 341 ms 121204 KiB
03_handmade_07.txt AC 58 ms 76640 KiB
03_handmade_08.txt AC 59 ms 76776 KiB