結果

問題 No.417 チューリップバブル
ユーザー autumn-eelautumn-eel
提出日時 2018-02-05 13:52:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 169,068 KB
実行使用メモリ 7,024 KB
最終ジャッジ日時 2023-09-21 21:12:52
合計ジャッジ時間 8,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 12 ms
4,384 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 67 ms
4,376 KB
testcase_12 AC 66 ms
4,380 KB
testcase_13 AC 25 ms
4,376 KB
testcase_14 AC 106 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 57 ms
4,380 KB
testcase_18 AC 56 ms
4,396 KB
testcase_19 AC 57 ms
4,376 KB
testcase_20 AC 221 ms
4,716 KB
testcase_21 AC 219 ms
4,596 KB
testcase_22 AC 219 ms
4,624 KB
testcase_23 AC 219 ms
4,680 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 221 ms
4,644 KB
testcase_26 AC 21 ms
4,376 KB
testcase_27 AC 152 ms
4,500 KB
testcase_28 AC 218 ms
4,716 KB
testcase_29 AC 216 ms
4,664 KB
testcase_30 AC 217 ms
4,604 KB
testcase_31 AC 217 ms
4,600 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 7 ms
4,380 KB
testcase_34 AC 45 ms
4,376 KB
testcase_35 AC 445 ms
7,024 KB
testcase_36 AC 447 ms
6,708 KB
testcase_37 AC 449 ms
6,780 KB
testcase_38 AC 449 ms
6,932 KB
testcase_39 AC 450 ms
6,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0