結果

問題 No.417 チューリップバブル
ユーザー hirokazu1020hirokazu1020
提出日時 2016-08-27 01:17:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 98,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 05:44:06
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 42 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 46 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 30 ms
5,376 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 AC 31 ms
5,376 KB
testcase_20 AC 112 ms
5,376 KB
testcase_21 AC 125 ms
5,376 KB
testcase_22 AC 116 ms
5,376 KB
testcase_23 AC 112 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 101 ms
5,376 KB
testcase_26 AC 12 ms
5,376 KB
testcase_27 AC 81 ms
5,376 KB
testcase_28 AC 122 ms
5,376 KB
testcase_29 AC 117 ms
5,376 KB
testcase_30 AC 125 ms
5,376 KB
testcase_31 AC 120 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 11 ms
5,376 KB
testcase_35 AC 217 ms
5,376 KB
testcase_36 AC 237 ms
5,376 KB
testcase_37 AC 175 ms
5,376 KB
testcase_38 AC 197 ms
5,376 KB
testcase_39 AC 200 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



long long dp[200][1001];
int n, m;
int U[200];
vector<pair<int, int> > edge[200];


long long f(int u, int t, int par) {
	if (dp[u][m] != -1)return dp[u][t];
	dp[u][0] = U[u];
	for (auto p : edge[u]) {
		if (par == p.first)continue;

		for (int i = m - p.second; i >= 0; i--)if (dp[u][i] != -1){
			for (int j = 0; j <=  m - i - p.second; j++) {
				dp[u][i + p.second + j] = max(dp[u][i + p.second + j],
					dp[u][i] + f(p.first, j , u));
			}
		}
	}
	for (int i = 1; i <= m; i++)dp[u][i] = max(dp[u][i], dp[u][i - 1]);
	return dp[u][t];
}







int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	m /= 2;
	rep(i, n)cin >> U[i];
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		edge[a].emplace_back(b, c);
		edge[b].emplace_back(a, c);
	}
	memset(dp, -1, sizeof(dp));
	cout << f(0, m, -1) << endl;

	return 0;
}
0