結果

問題 No.807 umg tours
コンテスト
ユーザー ntuda
提出日時 2021-09-13 21:57:16
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 798 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 85,464 KB
実行使用メモリ 322,116 KB
最終ジャッジ日時 2026-03-12 10:32:39
合計ジャッジ時間 67,355 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 RE * 10 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]
E = [[] for _ in range(N)]
for a,b,c in ABC:
    E[a-1].append([b-1,c])
    E[b-1].append([a-1,c])

dp1 = [10**18] * N
dp2 = [10**18] * N
dp1[0] = 0
dp2[0] = 0
def dfs1(x,maxc,cost,path):
    for to,c in E[x]:
        if to in path:
            continue
        else:
            maxct = max(maxc,c)
            costt = cost + c
            dp1[to] = min(dp1[to],costt - maxct)
            dfs1(to,maxct,costt,path | {to})
def dfs2(x,cost,path):
    for to,c in E[x]:
        if to in path:
            continue
        else:
            costt = cost + c
            dp2[to] = min(dp2[to],costt)
            dfs2(to,costt,path | {to})

dfs1(0,0,0,{0})
dfs2(0,0,{0})

for i in range(N):
    print(dp1[i]+dp2[i])
0