結果

問題 No.807 umg tours
ユーザー kohei2019kohei2019
提出日時 2022-04-14 01:19:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,392 ms / 4,000 ms
コード長 723 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 169,924 KB
最終ジャッジ日時 2023-08-25 17:48:48
合計ジャッジ時間 15,601 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,100 KB
testcase_01 AC 83 ms
76,452 KB
testcase_02 AC 88 ms
76,448 KB
testcase_03 AC 80 ms
76,212 KB
testcase_04 AC 77 ms
76,464 KB
testcase_05 AC 79 ms
76,176 KB
testcase_06 AC 87 ms
76,300 KB
testcase_07 AC 86 ms
76,544 KB
testcase_08 AC 67 ms
71,508 KB
testcase_09 AC 69 ms
71,304 KB
testcase_10 AC 71 ms
71,512 KB
testcase_11 AC 775 ms
140,212 KB
testcase_12 AC 794 ms
128,692 KB
testcase_13 AC 1,016 ms
147,588 KB
testcase_14 AC 512 ms
108,804 KB
testcase_15 AC 392 ms
101,312 KB
testcase_16 AC 1,039 ms
152,944 KB
testcase_17 AC 1,260 ms
165,264 KB
testcase_18 AC 1,263 ms
165,584 KB
testcase_19 AC 1,161 ms
161,412 KB
testcase_20 AC 658 ms
125,496 KB
testcase_21 AC 701 ms
129,132 KB
testcase_22 AC 324 ms
99,456 KB
testcase_23 AC 336 ms
96,540 KB
testcase_24 AC 610 ms
156,120 KB
testcase_25 AC 1,392 ms
169,924 KB
権限があれば一括ダウンロードができます

ソースコード

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
cost[N] = 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