結果

問題 No.417 チューリップバブル
ユーザー Div9851Div9851
提出日時 2017-10-06 17:40:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 162,164 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 10:23:18
合計ジャッジ時間 5,498 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 41 ms
5,376 KB
testcase_12 AC 43 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 69 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 36 ms
5,376 KB
testcase_18 AC 36 ms
5,376 KB
testcase_19 AC 36 ms
5,376 KB
testcase_20 AC 140 ms
5,376 KB
testcase_21 AC 136 ms
5,376 KB
testcase_22 AC 139 ms
5,376 KB
testcase_23 AC 144 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 142 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 96 ms
5,376 KB
testcase_28 AC 141 ms
5,376 KB
testcase_29 AC 137 ms
5,376 KB
testcase_30 AC 138 ms
5,376 KB
testcase_31 AC 137 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 29 ms
5,376 KB
testcase_35 AC 277 ms
5,376 KB
testcase_36 AC 282 ms
5,376 KB
testcase_37 AC 282 ms
5,376 KB
testcase_38 AC 280 ms
5,376 KB
testcase_39 AC 278 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int dp[200][2001];
vector<PI> G[200];
int U[200];
int N, M;
void dfs(int v, int par) {
	rep(i, M + 1) dp[v][i] = U[v];
	rep(i, G[v].size()) {
		int to = G[v][i].first;
		int cost = G[v][i].second;
		if (to == par) continue;
		dfs(to, v);
		for (int j = M; j >= 0; j--) {
			for (int k = 0; k + cost <= j; k++) {
				dp[v][j] = max(dp[v][j], dp[v][j - (k + cost)] + dp[to][k]);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	rep(i, N) {
		cin >> U[i];
	}
	rep(i, N - 1) {
		int A, B, C;
		cin >> A >> B >> C;
		G[A].push_back(MP(B, C * 2));
		G[B].push_back(MP(A, C * 2));
	}
	dfs(0, -1);
	cout << dp[0][M] << endl;
}
0