結果
問題 | No.1488 Max Score of the Tree |
ユーザー |
![]() |
提出日時 | 2021-04-23 23:31:12 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 614 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 25,088 KB |
最終ジャッジ日時 | 2024-07-04 08:47:59 |
合計ジャッジ時間 | 6,494 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 2 -- * 27 |
ソースコード
def dfs(G,v,p,sz,edge): cnt=0 for nv,c in G[v]: if nv==p: continue cnt+=1 dfs(G,nv,v,sz,edge) sz[v]+=sz[nv] edge.append([c,sz[nv]]) if cnt==0: sz[v]=1 N,K=map(int,input().split()) G=[[] for i in range(N)] for _ in range(N-1): a,b,c=map(int,input().split()) a-=1 b-=1 G[a].append([b,c]) G[b].append([a,c]) sz=[0]*N edge=[] dfs(G,0,-1,sz,edge) ans=0 dp=[0]*(K+1) for e,cnt in edge: ans+=e*cnt for i in range(K,-1,-1): if i-e<0: break; dp[i]=max(dp[i],dp[i-e]+cnt*e) print(ans+max(dp))