結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2021-09-13 21:57:16 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 798 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 120,736 KB |
最終ジャッジ日時 | 2024-06-25 23:05:23 |
合計ジャッジ時間 | 12,879 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 25 |
ソースコード
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])