結果

問題 No.417 チューリップバブル
ユーザー doikimihirodoikimihiro
提出日時 2018-08-04 14:24:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 171,220 KB
実行使用メモリ 5,408 KB
最終ジャッジ日時 2023-10-19 21:49:42
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 21 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 12 ms
4,620 KB
testcase_18 AC 12 ms
4,620 KB
testcase_19 AC 12 ms
4,620 KB
testcase_20 AC 41 ms
4,624 KB
testcase_21 AC 40 ms
4,624 KB
testcase_22 AC 41 ms
4,624 KB
testcase_23 AC 41 ms
4,624 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 41 ms
4,624 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 29 ms
4,392 KB
testcase_28 AC 40 ms
4,624 KB
testcase_29 AC 40 ms
4,624 KB
testcase_30 AC 41 ms
4,624 KB
testcase_31 AC 40 ms
4,624 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 10 ms
4,348 KB
testcase_35 AC 80 ms
5,408 KB
testcase_36 AC 80 ms
5,408 KB
testcase_37 AC 81 ms
5,408 KB
testcase_38 AC 81 ms
5,408 KB
testcase_39 AC 81 ms
5,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
//http://kmjp.hatenablog.jp/entry/2016/08/27/0930
int N, M;
int U[1000];
ll dp[200][1001];
vector<pair<int, int>>E[200];
void dfs(int p, int c0) {
	for (int i = 0; i <= M; i++) {
		dp[c0][i] = U[c0];//dp[親][時間]を親地点の獲得ポイントで初期化
	}
	for (auto e : E[c0]) {
		if (e.first != p) {//子が親でなければ
			int c1 = e.first;
			int cost = e.second;
			dfs(c0, c1);
			for (int i = M; i >= 0; i--) {
				for (int j = 0; j + cost <= i; j++) {
					dp[c0][i] = max(dp[c0][i], dp[c0][i - (j + cost)] + dp[c1][j]);
				}
			}
		}
	}
}
int main() {
	scanf("%d %d", &N, &M);
	M /= 2;
	for (int i = 0; i < N; i++) {
		scanf("%d", &U[i]);
	}
	for (int i = 0; i < N - 1; i++) {
		int from, to, cost;
		scanf("%d %d %d", &from, &to, &cost);
		E[from].push_back(make_pair(to, cost));
		E[to].push_back(make_pair(from, cost));
	}
	dfs(-1, 0);
	printf("%lld\n", *max_element(dp[0], dp[0] + M + 1));

}
0