結果
問題 | No.417 チューリップバブル |
ユーザー |
![]() |
提出日時 | 2016-08-26 22:55:34 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 464 ms / 2,000 ms |
コード長 | 1,272 bytes |
コンパイル時間 | 1,378 ms |
コンパイル使用メモリ | 160,484 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-11-08 09:41:47 |
合計ジャッジ時間 | 7,554 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | scanf("%lld%lld",&N,&M); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:41:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | rep(i,N)scanf("%lld",&U[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%lld%lld%lld",&a,&b,&c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;#define int long longtypedef vector<int>vint;typedef pair<int,int>pint;typedef vector<pint>vpint;#define rep(i,n) for(int i=0;i<(n);i++)#define reps(i,f,n) for(int i=(f);i<(n);i++)#define all(v) (v).begin(),(v).end()#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)#define pb push_back#define fi first#define se secondtemplate<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}struct edge{int to,cost;edge(int to,int cost):to(to),cost(cost){}};int N,M;int U[200];vector<edge>G[200];int dp[200][2001];void dfs(int v,int p){rep(i,M+1)dp[v][i]=U[v];for(auto e:G[v]){if(e.to==p)continue;dfs(e.to,v);for(int i=M;i-e.cost*2>=0;i--){for(int j=0;j+e.cost*2<=i;j++){chmax(dp[v][i],dp[v][i-j-e.cost*2]+dp[e.to][j]);}}}}signed main(){scanf("%lld%lld",&N,&M);rep(i,N)scanf("%lld",&U[i]);rep(i,N-1){int a,b,c;scanf("%lld%lld%lld",&a,&b,&c);G[a].pb(edge(b,c));G[b].pb(edge(a,c));}dfs(0,-1);printf("%lld\n",dp[0][M]);return 0;}