結果

問題 No.417 チューリップバブル
ユーザー HAHAHAHAHAHA
提出日時 2016-09-02 13:20:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 162,360 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 14:59:12
合計ジャッジ時間 3,850 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 5 ms
6,944 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 10 ms
6,940 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 18 ms
6,940 KB
testcase_12 AC 18 ms
6,940 KB
testcase_13 AC 29 ms
6,944 KB
testcase_14 AC 28 ms
6,940 KB
testcase_15 AC 29 ms
6,940 KB
testcase_16 AC 28 ms
6,944 KB
testcase_17 AC 55 ms
6,940 KB
testcase_18 AC 55 ms
6,944 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 55 ms
6,940 KB
testcase_21 AC 59 ms
6,944 KB
testcase_22 AC 55 ms
6,940 KB
testcase_23 AC 57 ms
6,940 KB
testcase_24 AC 56 ms
6,940 KB
testcase_25 AC 57 ms
6,940 KB
testcase_26 AC 41 ms
6,944 KB
testcase_27 AC 40 ms
6,940 KB
testcase_28 AC 55 ms
6,944 KB
testcase_29 AC 56 ms
6,940 KB
testcase_30 AC 56 ms
6,940 KB
testcase_31 AC 54 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 12 ms
6,944 KB
testcase_35 AC 107 ms
6,940 KB
testcase_36 AC 109 ms
6,944 KB
testcase_37 AC 113 ms
6,940 KB
testcase_38 AC 119 ms
6,940 KB
testcase_39 AC 114 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;


// not...
struct edge{
	int next;
	long long cost;
};

void chmax(long long &a, long long b){
	if(a<b) a=b;
}

const long long INF = 1e17;
int n,m;
vector<edge> v[200];
long long A[200];
long long dp[250][1100];


void dfs(int a, int b){
	for(int i=0;i<1010;i++){
		dp[a][i]=-INF;
	}
	dp[a][0]=A[a];
	for(edge e : v[a]) if(e.next!= b){
		dfs(e.next,a);
		for(int i=1000;i>=0;i--){
			if(dp[a][i]==INF) continue;
			for(int j=0;i+j+e.cost<=1000;j++){
				chmax(dp[a][i+j+e.cost] , dp[a][i]+dp[e.next][j]);
			}
		}
	}
}

int main(){
	cin >> n >> m;
	m/=2;
	
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
			v[a].push_back({b,c});
			v[b].push_back({a,c});
	}
	
	dfs(0,-1);
	long long ans =0;
	for(int i=0;i<=m;i++)
		chmax(ans,dp[0][i]);
	
	cout << ans << endl;
	return 0;
}
0