結果

問題 No.807 umg tours
ユーザー hedwig100hedwig100
提出日時 2020-04-23 23:13:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 119,548 KB
最終ジャッジ日時 2024-04-22 03:46:54
合計ジャッジ時間 11,309 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,312 KB
testcase_01 AC 39 ms
55,624 KB
testcase_02 AC 47 ms
64,388 KB
testcase_03 AC 47 ms
62,948 KB
testcase_04 AC 39 ms
55,280 KB
testcase_05 AC 39 ms
55,868 KB
testcase_06 AC 46 ms
62,084 KB
testcase_07 AC 43 ms
62,776 KB
testcase_08 AC 35 ms
54,004 KB
testcase_09 AC 37 ms
53,320 KB
testcase_10 AC 37 ms
54,800 KB
testcase_11 AC 568 ms
101,812 KB
testcase_12 AC 601 ms
101,472 KB
testcase_13 AC 762 ms
109,532 KB
testcase_14 AC 407 ms
91,700 KB
testcase_15 AC 326 ms
88,668 KB
testcase_16 AC 736 ms
111,660 KB
testcase_17 AC 874 ms
118,308 KB
testcase_18 AC 876 ms
117,588 KB
testcase_19 AC 902 ms
117,624 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 370 ms
113,512 KB
testcase_25 AC 915 ms
119,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heapify,heappush,heappop
input = sys.stdin.readline
INF = 10 ** 9 + 7

n,m = map(int,input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append((b,c))
    G[b].append((a,c))

dist = [INF] * n
dist[0] = 0

q = [(0,0)]
heapify(q)

while q:
    d,v = heappop(q)
    if dist[v] < d:
        continue
    for e,cost in G[v]:
        if dist[e] > dist[v] + cost:
            dist[e] = dist[v] + cost
            heappush(q,(dist[e],e))

dist1 = [INF] * n
dist1[0] = 0
heappush(q,(0,0))
while q:
    d,v = heappop(q)
    if dist1[v] < d:
        continue
    for e,cost in G[v]:
        m = min(dist[v],dist1[v] + cost)
        if dist1[e] > m:
            dist1[e] = m
            heappush(q,(dist1[e],e))

print('\n'.join(map(str,[dist[i] + dist1[i] for i in range(n)])))
0