結果

問題 No.417 チューリップバブル
ユーザー ttkkggwwttkkggww
提出日時 2020-04-01 15:54:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,306 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 172,628 KB
実行使用メモリ 632,384 KB
最終ジャッジ日時 2023-09-09 05:28:21
合計ジャッジ時間 16,659 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,940 KB
testcase_01 AC 31 ms
25,876 KB
testcase_02 AC 31 ms
25,880 KB
testcase_03 AC 31 ms
25,880 KB
testcase_04 AC 8 ms
11,548 KB
testcase_05 AC 8 ms
11,864 KB
testcase_06 AC 36 ms
30,052 KB
testcase_07 AC 35 ms
29,972 KB
testcase_08 AC 70 ms
54,536 KB
testcase_09 AC 71 ms
54,692 KB
testcase_10 AC 143 ms
105,916 KB
testcase_11 AC 144 ms
105,888 KB
testcase_12 AC 143 ms
105,816 KB
testcase_13 AC 227 ms
161,064 KB
testcase_14 AC 226 ms
161,128 KB
testcase_15 AC 230 ms
161,180 KB
testcase_16 AC 231 ms
161,048 KB
testcase_17 AC 471 ms
317,588 KB
testcase_18 AC 463 ms
317,640 KB
testcase_19 AC 464 ms
318,884 KB
testcase_20 AC 461 ms
317,644 KB
testcase_21 AC 461 ms
318,732 KB
testcase_22 AC 466 ms
318,744 KB
testcase_23 AC 461 ms
318,940 KB
testcase_24 AC 461 ms
319,076 KB
testcase_25 AC 461 ms
317,720 KB
testcase_26 AC 324 ms
224,536 KB
testcase_27 AC 321 ms
224,668 KB
testcase_28 AC 460 ms
318,748 KB
testcase_29 AC 459 ms
318,728 KB
testcase_30 AC 459 ms
318,764 KB
testcase_31 AC 461 ms
318,748 KB
testcase_32 AC 6 ms
11,824 KB
testcase_33 AC 19 ms
19,744 KB
testcase_34 AC 161 ms
161,108 KB
testcase_35 MLE -
testcase_36 MLE -
testcase_37 MLE -
testcase_38 MLE -
testcase_39 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[201][201][2001];
//dp[i][j][k]
//iを頂点とした、jをの子までを選んでkのタイムでの最大の税収
//iそれぞれでナップサックみたいな感じ
vector<vector<pair<int,int>>> M;
vector<int> tax;
void dfs(int now,int p = -1)
{
	//cout<<now<<endl;
	for(int i = 0;i<201;i++)
	{
		for(int j = 0;j <2001;j++)
		{
			dp[now][i][j] = tax[now];
		}
	}
	int I = 0;
	for(int i = 0;i<M[now].size();i++)
	{
		if(M[now][i].first!=p)
		{
			dfs(M[now][i].first,now);
			for(int j = 0;j<2001;j++)
			{
				if(j-M[now][i].second<0)
				{
					dp[now][I+1][j] = dp[now][I][j];
					continue;
				}
				for(int k = 0;j-M[now][i].second-k>=0;k++)
				{
					dp[now][I+1][j] = max(max(dp[now][I][j],
								dp[now][I+1][j]),
					dp[now][I][j-M[now][i].second-k]
					+dp[M[now][i].first][0][k]);
				}
			}
			I++;
		}
	}
	for(int i = 0;i<2001;i++)
	{
		dp[now][0][i] = dp[now][I][i];
	}
}


int main()
{
	int n;
	cin >> n;
	int m;
	cin >> m;
	tax = vector<int>(n);
	for(int i = 0;i<n;i++)
	{
		cin >> tax[i];
	}
	M = vector<vector<pair<int,int>>>(n);
	for(int i = 0;i<n-1;i++)
	{
		int x,y,z;
		cin >> x >> y >> z;
		M[x].emplace_back(y,z);
		M[y].emplace_back(x,z);
	}
	dfs(0);
	cout<<dp[0][0][m/2]<<endl;
	return 0;
}
0