結果

問題 No.807 umg tours
ユーザー KentarokumuraKentarokumura
提出日時 2019-03-22 23:16:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,025 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 182,996 KB
最終ジャッジ日時 2023-10-19 10:44:32
合計ジャッジ時間 21,786 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 56 ms
65,820 KB
testcase_07 WA -
testcase_08 AC 44 ms
55,524 KB
testcase_09 AC 44 ms
55,524 KB
testcase_10 AC 46 ms
55,524 KB
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 AC 489 ms
97,796 KB
testcase_21 AC 491 ms
99,948 KB
testcase_22 AC 269 ms
85,688 KB
testcase_23 AC 242 ms
83,872 KB
testcase_24 AC 391 ms
111,528 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
from collections import deque
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):
    visit=[False]*N
    visit[x]=True
    H=deque()
    H.append(x)
    while H:
        z=H.popleft()
        for y,c in table[z]:
            if not visit[y]:
                dp[y]=min(dp[y],dp[z]+c,cost[z])
                visit[y]=True
                H.append(y)
    return
f(0)
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