結果

問題 No.807 umg tours
ユーザー ntudantuda
提出日時 2021-09-13 21:57:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 798 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 112,076 KB
最終ジャッジ日時 2023-09-08 05:51:46
合計ジャッジ時間 12,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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