結果

問題 No.807 umg tours
ユーザー KentarokumuraKentarokumura
提出日時 2019-03-22 23:10:29
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 889 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,616 KB
実行使用メモリ 181,312 KB
最終ジャッジ日時 2023-10-19 10:23:56
合計ジャッジ時間 20,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from heapq import heappop,heappush
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    table[a].append((b,c))
    table[b].append((a,c))
H=[]
cost=[10**18]*N
cost[0]=0
H.append((0,0))
while H:
    pt,cos=heappop(H)
    if cost[pt]<cos:
        continue
    for y,c in table[pt]:
        if cost[y]>cost[pt]+c:
            cost[y]=cost[pt]+c
            heappush(H,(y,cost[y]))
dp=[10**19]*N
dp[0]=0
def f(x):
    if dp[x]!=10**19:
        return dp[x]
    for y,c in table[x]:
        dp[x]=min(dp[x],f(y)+c)
        dp[x]=min(dp[x],cost[y])
    return dp[x]
for i in range(N):
    f(i)
dp2=[10**19]*N
dp2[0]=0
for x in range(N):
    for y,c in table[x]:
        dp2[x]=min(dp2[x],dp[y]+c)
        dp2[x]=min(dp2[x],cost[y])
for i in range(N):
    print(dp2[i]+cost[i])

0