結果

問題 No.807 umg tours
ユーザー kohei2019kohei2019
提出日時 2022-04-14 01:18:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 170,884 KB
最終ジャッジ日時 2023-08-25 17:47:41
合計ジャッジ時間 16,376 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N,M = map(int,input().split())
lsg = [[] for i in range(2*N)]
for i in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    lsg[a].append((b,c))
    lsg[b].append((a,c))
    lsg[a].append((b+N,0))
    lsg[b].append((a+N,0))
    lsg[a+N].append((b+N,c))
    lsg[b+N].append((a+N,c))

h = [(0,0)]
INF = float('INF')
cost = [INF]*(2*N)
cost[0] = 0
used = [False]*(2*N)
while h:
    c,n = heapq.heappop(h)
    if used[n]:
        continue
    used[n] = True
    for nex,cos in lsg[n]:
        if used[nex]:
            continue
        if cost[nex] > c + cos:
            cost[nex] = c + cos
            heapq.heappush(h, (c+cos,nex))
for i in range(N):
    print(cost[i]+cost[i+N])
0