結果

問題 No.417 チューリップバブル
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-06-29 10:09:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 72,384 KB
実行使用メモリ 5,468 KB
最終ジャッジ日時 2023-08-07 13:34:43
合計ジャッジ時間 5,784 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 54 ms
4,380 KB
testcase_12 AC 53 ms
4,380 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 85 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 45 ms
4,428 KB
testcase_18 AC 46 ms
4,448 KB
testcase_19 AC 46 ms
4,476 KB
testcase_20 AC 176 ms
4,380 KB
testcase_21 AC 175 ms
4,376 KB
testcase_22 AC 174 ms
4,380 KB
testcase_23 AC 174 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 175 ms
4,380 KB
testcase_26 AC 17 ms
4,376 KB
testcase_27 AC 121 ms
4,376 KB
testcase_28 AC 174 ms
4,380 KB
testcase_29 AC 172 ms
4,380 KB
testcase_30 AC 172 ms
4,396 KB
testcase_31 AC 172 ms
4,484 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 36 ms
4,376 KB
testcase_35 AC 354 ms
5,120 KB
testcase_36 AC 353 ms
5,232 KB
testcase_37 AC 357 ms
5,308 KB
testcase_38 AC 356 ms
5,468 KB
testcase_39 AC 359 ms
5,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//このコードを模範解答としてください。
#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<string.h>

const int LIMITM=2001;
const int LIMITN=201;
int dp[LIMITN][LIMITM];
std::map<int,int> tree[LIMITN];
int taxes[LIMITN];
int n,m;
void f(int oya,int now){
	memset(dp[now],0,sizeof(dp[now]));
	std::map<int,int>::iterator it;
	for(it=tree[now].begin();it!=tree[now].end();it++){
		int next=(*it).first;
		int time=(*it).second*2;
		if(oya==next){
			continue;
		}
		f(now,next);
		int temp[LIMITM];
		memcpy(temp,dp[now],sizeof(dp[now]));
		for(int i=0;i+time<=m;i++){
			for(int j=0;j+i+time<=m;j++){
				int nextTime=j+i+time;
				int nextTax=dp[now][i]+dp[next][j];
				temp[nextTime]=std::max(temp[nextTime],nextTax);
			}
		}
		memcpy(dp[now],temp,sizeof(temp));
	}
	for(int i=0;i<=m;i++){
		dp[now][i]+=taxes[now];
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&taxes[i]);
	}
	for(int i=0;i<n-1;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		tree[a][b]=c;
		tree[b][a]=c;
	}
	f(-1,0);
	int ans=0;
	for(int i=0;i<=m;i++){
		ans=std::max(ans,dp[0][i]);
	}
	printf("%d\n",ans);
}
0