結果

問題 No.807 umg tours
ユーザー silversmithsilversmith
提出日時 2019-04-07 13:22:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 171,260 KB
最終ジャッジ日時 2023-09-09 07:05:40
合計ジャッジ時間 18,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
75,600 KB
testcase_01 AC 104 ms
76,396 KB
testcase_02 AC 103 ms
76,272 KB
testcase_03 AC 103 ms
76,176 KB
testcase_04 AC 96 ms
75,420 KB
testcase_05 AC 98 ms
75,732 KB
testcase_06 AC 104 ms
76,696 KB
testcase_07 AC 99 ms
75,860 KB
testcase_08 AC 88 ms
71,140 KB
testcase_09 AC 89 ms
71,216 KB
testcase_10 AC 89 ms
71,140 KB
testcase_11 AC 998 ms
139,276 KB
testcase_12 AC 1,004 ms
127,980 KB
testcase_13 AC 1,258 ms
147,564 KB
testcase_14 AC 640 ms
108,132 KB
testcase_15 AC 495 ms
101,528 KB
testcase_16 AC 1,315 ms
152,836 KB
testcase_17 AC 1,642 ms
166,060 KB
testcase_18 AC 1,589 ms
165,392 KB
testcase_19 AC 1,497 ms
161,692 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 675 ms
159,280 KB
testcase_25 AC 1,613 ms
171,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import os
import sys
import fileinput
import heapq

def main(file):
    N, M = map(int, file.readline().strip().split(' '))
    e=[[] for i in range(2 * N)]
    for i in range(M):
        v1, v2, cost = [int(x) for x in file.readline().strip().split(' ')]
        e[v1-1].append((v2-1,cost))
        e[v2-1].append((v1-1,cost))
        e[v1-1 + N].append((v2-1 + N,cost))
        e[v2-1 + N].append((v1-1 + N,cost))
        e[v1-1].append((v2-1 + N,0))
        e[v2-1].append((v1-1 + N,0))

    d = [10**9 + 1] * (2*N)
    d[0] = 0
    h = []
    heapq.heappush(h, (0,0))
    heapq.heappush(h, (0,N))
    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))


    print(0)
    for i in range(1,N):
        print(d[i] + d[i+N])
 
if __name__ == "__main__":
    file = sys.stdin
    main(file)
0