結果

問題 No.807 umg tours
ユーザー silversmithsilversmith
提出日時 2019-04-06 23:43:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 970 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 395,140 KB
最終ジャッジ日時 2023-09-07 11:16:51
合計ジャッジ時間 18,824 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
395,140 KB
testcase_01 AC 88 ms
76,152 KB
testcase_02 AC 96 ms
76,272 KB
testcase_03 AC 96 ms
76,152 KB
testcase_04 AC 81 ms
71,368 KB
testcase_05 AC 88 ms
76,144 KB
testcase_06 AC 95 ms
76,344 KB
testcase_07 AC 93 ms
76,160 KB
testcase_08 AC 80 ms
71,380 KB
testcase_09 AC 78 ms
71,256 KB
testcase_10 AC 80 ms
71,340 KB
testcase_11 AC 813 ms
104,156 KB
testcase_12 AC 857 ms
104,964 KB
testcase_13 AC 983 ms
111,820 KB
testcase_14 AC 609 ms
96,132 KB
testcase_15 AC 472 ms
91,144 KB
testcase_16 AC 1,052 ms
113,300 KB
testcase_17 AC 1,205 ms
120,744 KB
testcase_18 AC 1,235 ms
123,528 KB
testcase_19 AC 1,204 ms
119,992 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import os
import sys
import heapq

def main():
    N, M = map(int, input().split(' '))
    e=[[] for i in range(N)]
    for i in range(M):
        v1, v2, cost = [int(x) for x in input().split(' ')]
        e[v1-1].append((v2-1,cost))
        e[v2-1].append((v1-1,cost))

    d = [10**9 + 1] * N
    d_exe = [10**9 +1] * N
    d[0] = 0
    d_exe[0] = 0
    h = []
    heapq.heappush(h, (0,0))
    while h:
        c, j = heapq.heappop(h)
        if d[j]<c: continue
        for i,cost in e[j]:
            alt = c + cost
            if d[i] < alt : continue
            d[i] = alt
            heapq.heappush(h,(alt, i))


    h = []
    heapq.heappush(h, (0,0))
    while h:
        c,j = heapq.heappop(h)
        if d[j]<c: continue
        for i, cost in e[j]:
            alt = min(c + cost,d[j])
            if d_exe[i] < alt : continue
            d_exe[i] = alt
            heapq.heappush(h,(alt, i))

    for i in range(N):
        print(d[i] + d_exe[i])

main()
0