結果

問題 No.417 チューリップバブル
ユーザー FF256grhyFF256grhy
提出日時 2016-08-27 02:13:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 24,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 05:45:35
合計ジャッジ時間 4,763 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 50 ms
5,376 KB
testcase_12 AC 51 ms
5,376 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 77 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 41 ms
5,376 KB
testcase_18 AC 42 ms
5,376 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 160 ms
5,376 KB
testcase_21 AC 160 ms
5,376 KB
testcase_22 AC 155 ms
5,376 KB
testcase_23 AC 159 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 160 ms
5,376 KB
testcase_26 AC 15 ms
5,376 KB
testcase_27 AC 111 ms
5,376 KB
testcase_28 AC 159 ms
5,376 KB
testcase_29 AC 159 ms
5,376 KB
testcase_30 AC 158 ms
5,376 KB
testcase_31 AC 161 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 76 ms
5,376 KB
testcase_35 AC 317 ms
5,376 KB
testcase_36 AC 319 ms
5,376 KB
testcase_37 AC 310 ms
5,376 KB
testcase_38 AC 314 ms
5,376 KB
testcase_39 AC 311 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:33:47: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |         for(int i = 0; i < n    ; i++) { scanf("%d", &u[i]); }
      |                                          ~~~~~^~~~~~~~~~~~~
main.cpp:34:47: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         for(int i = 0; i < n - 1; i++) { scanf("%d%d%d", &a[i], &b[i], &c[i]); }
      |                                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int n, m, u[200], a[199], b[199], c[199];
int ne[200][199], tm[200][199], ne_num[200];
int dp[200][2001];

void search(int x, int p) {
	for(int i = 0; i <= m; i++) { dp[x][i] = u[x]; }
	
	for(int i = 0; i < ne_num[x]; i++) { if(ne[x][i] != p) { search(ne[x][i], x); } }
	for(int i = 0; i < ne_num[x]; i++) {
		if(ne[x][i] != p) {
			int cp[2001];
			for(int j = 0; j <= m; j++) { cp[j] = dp[x][j]; }
			
			for(int s = 0; s <= m; s++) {
			for(int j = 0; j <= s; j++) {
				int v = dp[x][j] + dp[ ne[x][i] ][s - j];
				int t = s + tm[x][i] * 2;
				if(t <= m && cp[t] < v) { cp[t] = v; }
			}
			}
			
			for(int j = 0; j <= m; j++) { dp[x][j] = cp[j]; }
		}
	}
	
	return;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n    ; i++) { scanf("%d", &u[i]); }
	for(int i = 0; i < n - 1; i++) { scanf("%d%d%d", &a[i], &b[i], &c[i]); }
	
	for(int i = 0; i < n - 1; i++) {
		ne[ a[i] ][ ne_num[ a[i] ]   ] = b[i];
		tm[ a[i] ][ ne_num[ a[i] ]++ ] = c[i];
		ne[ b[i] ][ ne_num[ b[i] ]   ] = a[i];
		tm[ b[i] ][ ne_num[ b[i] ]++ ] = c[i];
	}
	
	search(0, -1);
	
	printf("%d\n", dp[0][m]);
	
	return 0;
}
0