結果
問題 | No.417 チューリップバブル |
ユーザー |
|
提出日時 | 2020-02-23 16:54:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 311 ms / 2,000 ms |
コード長 | 682 bytes |
コンパイル時間 | 645 ms |
コンパイル使用メモリ | 74,052 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-10 03:53:18 |
合計ジャッジ時間 | 5,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
コンパイルメッセージ
main.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 26 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; int N,M; int U[200]; vector<pair<int,int> >G[200]; int dp[200][2001]; void dfs(int u,int p) { dp[u][0]=U[u]; for(pair<int,int>q:G[u]) { int v=q.first,cost=q.second; if(v==p)continue; dfs(v,u); for(int i=M;i>=2*cost;i--) { for(int j=0;j<=i-2*cost;j++) { dp[u][i]=max(dp[u][i],dp[u][j]+dp[v][i-2*cost-j]); } } } } main() { cin>>N>>M; for(int i=0;i<N;i++)cin>>U[i]; for(int i=1;i<N;i++) { int u,v,c;cin>>u>>v>>c; G[u].push_back(make_pair(v,c)); G[v].push_back(make_pair(u,c)); } dfs(0,-1); int ans=0; for(int i=0;i<=M;i++)ans=max(ans,dp[0][i]); cout<<ans<<endl; }