結果

問題 No.417 チューリップバブル
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-06-29 09:03:48
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,106 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 69,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:17:02
合計ジャッジ時間 7,901 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d %d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:41:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |                 scanf("%d",&taxes[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 scanf("%d %d %d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/string.h:535,
                 from main.cpp:5:
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘void f(int, int)’ at main.cpp:24:9:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:33: warning: ‘void* __builtin___memcpy_chk(void*, const void*, long unsigned int, long unsigned int)’ writing 8004 bytes into a region of size 8000 overflows the destination [-Wstringop-overflow=]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<string.h>

const int LIMITM=2000;
const int LIMITN=100;
int dp[LIMITN][LIMITM+1];
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