結果

問題 No.417 チューリップバブル
ユーザー pekempeypekempey
提出日時 2016-08-26 23:03:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 162,928 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 21:42:48
合計ジャッジ時間 4,074 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 6 ms
6,944 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 11 ms
6,944 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 21 ms
6,940 KB
testcase_11 AC 21 ms
6,948 KB
testcase_12 AC 22 ms
6,940 KB
testcase_13 AC 33 ms
6,940 KB
testcase_14 AC 35 ms
6,940 KB
testcase_15 AC 36 ms
6,944 KB
testcase_16 AC 36 ms
6,944 KB
testcase_17 AC 71 ms
6,940 KB
testcase_18 AC 68 ms
6,940 KB
testcase_19 AC 70 ms
6,944 KB
testcase_20 AC 69 ms
6,944 KB
testcase_21 AC 69 ms
6,940 KB
testcase_22 AC 70 ms
6,940 KB
testcase_23 AC 69 ms
6,940 KB
testcase_24 AC 70 ms
6,940 KB
testcase_25 AC 71 ms
6,940 KB
testcase_26 AC 50 ms
6,944 KB
testcase_27 AC 49 ms
6,940 KB
testcase_28 AC 69 ms
6,940 KB
testcase_29 AC 69 ms
6,944 KB
testcase_30 AC 69 ms
6,944 KB
testcase_31 AC 69 ms
6,944 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 16 ms
6,944 KB
testcase_35 AC 139 ms
6,940 KB
testcase_36 AC 142 ms
6,944 KB
testcase_37 AC 142 ms
6,940 KB
testcase_38 AC 138 ms
6,940 KB
testcase_39 AC 142 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf("%lld", &u[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);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct edge {
	int next;
	long long cost;
};

const long long inf = 1e17;
int n, m;
vector<edge> g[200];
long long u[200];
long long dp[222][1010];

void chmax(long long &a, long long b) {
	if (a < b) a = b;
}

void dfs(int curr, int prev) {
	for (int i = 0; i < 1010; i++) {
		dp[curr][i] = -inf;
	}
	dp[curr][0] = u[curr];
	for (edge e : g[curr]) if (e.next != prev) {
		dfs(e.next, curr);
		for (int i = 1000; i >= 0; i--) {
			if (dp[curr][i] == inf) continue;
			for (int j = 0; i + j + e.cost <= 1000; j++) {
				chmax(dp[curr][i + j + e.cost], dp[curr][i] + dp[e.next][j]);
			}
		}
	}
}

int main() {
	cin >> n >> m;
	m /= 2;

	for (int i = 0; i < n; i++) {
		scanf("%lld", &u[i]);
	}

	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		g[a].push_back({ b, c });
		g[b].push_back({ a, c });
	}

	dfs(0, -1);

	long long ans = 0;
	for (int i = 0; i <= m; i++) chmax(ans, dp[0][i]);
	cout << ans << endl;
}
0