結果

問題 No.807 umg tours
ユーザー titia
提出日時 2019-03-22 22:04:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 770 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 149,504 KB
最終ジャッジ日時 2024-09-19 05:25:24
合計ジャッジ時間 12,545 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 RE * 9 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
E=[list(map(int,input().split())) for i in range(M)]

EDGE=[[] for i in range(N+1)]

for x,y,c in E:
    EDGE[x].append([y,c])
    EDGE[y].append([x,c])

MIN=[float("inf")]*(N+1)
MIN2=[float("inf")]*(N+1)

MIN[1]=0
MIN2[1]=0

def roadsearch(town,dist,maxdist):
    #print(town,dist,maxdist)
    for to,cost in EDGE[town]:
        Flag=0
        maxdist_town=max(maxdist,cost)

        if MIN[to]>dist+cost:
            MIN[to]=dist+cost
            Flag=1

        if MIN2[to]>dist+cost-maxdist_town:
            MIN2[to]=dist+cost-maxdist_town
            Flag=1

        if Flag:
            roadsearch(to,dist+cost,maxdist_town)

roadsearch(1,0,0)  

for i in range(1,N+1):
    print(MIN[i]+MIN2[i])
0