結果

問題 No.417 チューリップバブル
ユーザー chocopuuchocopuu
提出日時 2019-05-06 08:21:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 170,548 KB
実行使用メモリ 10,896 KB
最終ジャッジ日時 2023-09-09 08:11:23
合計ジャッジ時間 7,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,624 KB
testcase_01 AC 4 ms
10,628 KB
testcase_02 AC 4 ms
10,892 KB
testcase_03 AC 5 ms
10,764 KB
testcase_04 AC 4 ms
10,552 KB
testcase_05 AC 4 ms
10,592 KB
testcase_06 AC 4 ms
10,560 KB
testcase_07 AC 4 ms
10,892 KB
testcase_08 AC 8 ms
10,564 KB
testcase_09 AC 12 ms
10,596 KB
testcase_10 AC 15 ms
10,564 KB
testcase_11 AC 53 ms
10,568 KB
testcase_12 AC 54 ms
10,600 KB
testcase_13 AC 23 ms
10,636 KB
testcase_14 AC 85 ms
10,664 KB
testcase_15 AC 10 ms
10,596 KB
testcase_16 AC 10 ms
10,644 KB
testcase_17 AC 46 ms
10,896 KB
testcase_18 AC 46 ms
10,632 KB
testcase_19 AC 46 ms
10,624 KB
testcase_20 AC 171 ms
10,768 KB
testcase_21 AC 170 ms
10,572 KB
testcase_22 AC 170 ms
10,620 KB
testcase_23 AC 171 ms
10,568 KB
testcase_24 AC 4 ms
10,896 KB
testcase_25 AC 171 ms
10,708 KB
testcase_26 AC 19 ms
10,888 KB
testcase_27 AC 119 ms
10,624 KB
testcase_28 AC 169 ms
10,708 KB
testcase_29 AC 170 ms
10,600 KB
testcase_30 AC 172 ms
10,628 KB
testcase_31 AC 168 ms
10,696 KB
testcase_32 AC 5 ms
10,556 KB
testcase_33 AC 8 ms
10,556 KB
testcase_34 AC 37 ms
10,540 KB
testcase_35 AC 340 ms
10,636 KB
testcase_36 AC 337 ms
10,692 KB
testcase_37 AC 345 ms
10,580 KB
testcase_38 AC 341 ms
10,568 KB
testcase_39 AC 339 ms
10,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int N,M;
int u[202];
vpint g[2020];
int dp[303][3030];

void dfs(int now,int par){
	rep(i,0,M+1)dp[now][i] = u[now];
	for(auto e:g[now]){
		if(e.fi==par)continue;
		dfs(e.fi,now);
		rrep(i,0,M+1){
			rep(j,0,M+1){
				if(i<e.se*2+j)break;
				chmax(dp[now][i],dp[now][i-e.se*2-j]+dp[e.fi][j]);
			}
		}
	}
}

signed main()
{
	//IOS();
	cin>>N>>M;
	for(int i = 0;i < N;i++){
		cin>>u[i];
	}
	for(int i = 0;i < N-1;i++){
		int a,b,c;
		cin>>a>>b>>c;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	memset(dp,-1,sizeof(dp));
	dfs(0,-1);
	int ans = 0;
	rep(i,0,M+1)chmax(ans,dp[0][i]);
	cout<<ans<<endl;
}
0