結果
問題 |
No.417 チューリップバブル
|
ユーザー |
|
提出日時 | 2018-02-05 13:52:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 275 ms / 2,000 ms |
コード長 | 623 bytes |
コンパイル時間 | 1,363 ms |
コンパイル使用メモリ | 170,868 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-07-07 14:32:43 |
合計ジャッジ時間 | 5,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef pair<int,int>P; int u[500]; vector<P>E[500]; int dp[500][5000]; int n,m; void dfs(int v,int p){ rep(i,m+1)dp[v][i]=u[v]; for(auto u:E[v]){ if(u.second==p)continue; dfs(u.second,v); for(int i=m;i>=u.first*2;i--)for(int j=0;j+u.first*2<=i;j++){ dp[v][i]=max(dp[v][i],dp[v][j]+dp[u.second][i-j-u.first*2]); } } } int main(){ scanf("%d%d",&n,&m); rep(i,n)scanf("%d",&u[i]); rep(i,n-1){ int a,b,c;scanf("%d%d%d",&a,&b,&c); E[a].push_back(P(c,b)); E[b].push_back(P(c,a)); } dfs(0,-1); cout<<dp[0][m]<<endl; }