結果

問題 No.417 チューリップバブル
ユーザー doikimihirodoikimihiro
提出日時 2018-08-03 11:15:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,016 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 171,452 KB
実行使用メモリ 814,556 KB
最終ジャッジ日時 2023-10-19 21:17:04
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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 != c0) {//子が親でなければ
			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