Submission #22132326


Source Code Expand

import sys
import heapq

input = sys.stdin.readline


def dijkstra(edge, s):
    inf = 2**60
    dist = [0 if i == s else inf for i in range(len(edge))]
    q = [(0, s)]
    while q:
        d, p = heapq.heappop(q)
        if dist[p] < d:
            continue
        for c, to in edge[p]:
            if dist[to] > d + c:
                dist[to] = d + c
                heapq.heappush(q, (dist[to], to))

    return dist


def main():
    n, m = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        u, v, c = map(int, input().split())
        u -= 1
        v -= 1
        edge[u].append((c, v))
        edge[v].append((c, u))
    d0 = dijkstra(edge, 0)
    d1 = dijkstra(edge, n - 1)
    print(*(sum(i) for i in zip(d0, d1)), sep='\n')


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task 013 - Passing(★5)
User riantkb
Language Python (3.8.2)
Score 5
Code Size 817 Byte
Status AC
Exec Time 795 ms
Memory 59356 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 5 / 5
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_1.txt, sample_2.txt, sample_3.txt
All killer_1.txt, killer_2.txt, killer_3.txt, line_1.txt, line_2.txt, line_3.txt, rand_1.txt, rand_2.txt, rand_3.txt, rand_4.txt, rand_5.txt, rand_6.txt, rand_7.txt, sample_1.txt, sample_2.txt, sample_3.txt, star_1.txt, star_2.txt, star_3.txt
Case Name Status Exec Time Memory
killer_1.txt AC 54 ms 11624 KiB
killer_2.txt AC 481 ms 41560 KiB
killer_3.txt AC 19 ms 9104 KiB
line_1.txt AC 404 ms 54088 KiB
line_2.txt AC 457 ms 54080 KiB
line_3.txt AC 470 ms 54248 KiB
rand_1.txt AC 520 ms 45460 KiB
rand_2.txt AC 360 ms 37928 KiB
rand_3.txt AC 475 ms 43836 KiB
rand_4.txt AC 453 ms 41424 KiB
rand_5.txt AC 377 ms 38840 KiB
rand_6.txt AC 404 ms 38952 KiB
rand_7.txt AC 448 ms 41956 KiB
sample_1.txt AC 26 ms 9176 KiB
sample_2.txt AC 21 ms 8960 KiB
sample_3.txt AC 24 ms 8960 KiB
star_1.txt AC 795 ms 56212 KiB
star_2.txt AC 761 ms 59188 KiB
star_3.txt AC 739 ms 59356 KiB