結果

問題 No.417 チューリップバブル
ユーザー snrnsidysnrnsidy
提出日時 2021-04-28 00:59:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 360 ms / 2,000 ms
コード長 1,457 bytes
コンパイル時間 1,260 ms
コンパイル使用メモリ 132,600 KB
実行使用メモリ 5,220 KB
最終ジャッジ日時 2023-09-21 01:32:47
合計ジャッジ時間 6,635 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,072 KB
testcase_01 AC 2 ms
4,948 KB
testcase_02 AC 3 ms
4,956 KB
testcase_03 AC 3 ms
4,948 KB
testcase_04 AC 3 ms
5,012 KB
testcase_05 AC 3 ms
5,008 KB
testcase_06 AC 3 ms
4,972 KB
testcase_07 AC 3 ms
5,012 KB
testcase_08 AC 7 ms
4,904 KB
testcase_09 AC 13 ms
4,984 KB
testcase_10 AC 15 ms
5,080 KB
testcase_11 AC 66 ms
4,972 KB
testcase_12 AC 59 ms
4,972 KB
testcase_13 AC 21 ms
4,968 KB
testcase_14 AC 72 ms
4,956 KB
testcase_15 AC 8 ms
5,012 KB
testcase_16 AC 8 ms
4,888 KB
testcase_17 AC 45 ms
4,988 KB
testcase_18 AC 49 ms
5,220 KB
testcase_19 AC 47 ms
5,016 KB
testcase_20 AC 170 ms
4,976 KB
testcase_21 AC 191 ms
4,944 KB
testcase_22 AC 177 ms
4,884 KB
testcase_23 AC 170 ms
5,064 KB
testcase_24 AC 3 ms
4,912 KB
testcase_25 AC 153 ms
4,888 KB
testcase_26 AC 17 ms
5,008 KB
testcase_27 AC 124 ms
4,956 KB
testcase_28 AC 188 ms
5,132 KB
testcase_29 AC 180 ms
5,008 KB
testcase_30 AC 191 ms
4,948 KB
testcase_31 AC 185 ms
4,948 KB
testcase_32 AC 2 ms
4,884 KB
testcase_33 AC 8 ms
5,056 KB
testcase_34 AC 46 ms
5,064 KB
testcase_35 AC 326 ms
4,968 KB
testcase_36 AC 360 ms
5,152 KB
testcase_37 AC 263 ms
5,028 KB
testcase_38 AC 299 ms
4,948 KB
testcase_39 AC 295 ms
4,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;

int dp[201][2001];
int U[201];
vector <pair<int, int>> adj[201];
int N, M, A, B, C;

void solve(int now, int prev)
{
	dp[now][0] = U[now];
	for (auto it : adj[now])
	{
		int cost = it.second;
		int next = it.first;
		if (prev == next)
		{
			continue;
		}
		solve(next, now);
		for (int j = M; j >= 0; j--)
		{
			if (dp[now][j] == -1)
			{
				continue;
			}
			for (int k = M; k >= 0; k--)
			{
				if (j + k + 2 * cost <= M)
				{
					dp[now][j + k + 2 * cost] = max(dp[now][j + k + 2 * cost], dp[now][j] + dp[next][k]);
				}
			}
		}
	}
	return;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> M;

	for (int i = 0; i < N; i++)
	{
		cin >> U[i];
	}

	for (int i = 0; i < N - 1; i++)
	{
		cin >> A >> B >> C;
		adj[A].push_back(make_pair(B, C));
		adj[B].push_back(make_pair(A, C));
	}

	memset(dp, -1, sizeof(dp));

	solve(0, -1);
	
	int res = 0;	

	for (int i = 0; i <= M; i++)
	{
		res = max(res, dp[0][i]);
	}

	cout << res << '\n';

	return 0;
}
0