結果

問題 No.417 チューリップバブル
ユーザー sekiya9311sekiya9311
提出日時 2018-03-31 07:52:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 169,372 KB
実行使用メモリ 7,176 KB
最終ジャッジ日時 2023-09-08 07:59:50
合計ジャッジ時間 7,536 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 57 ms
4,376 KB
testcase_12 AC 55 ms
4,376 KB
testcase_13 AC 21 ms
4,376 KB
testcase_14 AC 87 ms
4,400 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 48 ms
4,884 KB
testcase_18 AC 47 ms
4,704 KB
testcase_19 AC 47 ms
4,668 KB
testcase_20 AC 180 ms
5,276 KB
testcase_21 AC 175 ms
5,264 KB
testcase_22 AC 171 ms
5,320 KB
testcase_23 AC 170 ms
5,288 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 173 ms
5,280 KB
testcase_26 AC 16 ms
4,380 KB
testcase_27 AC 119 ms
4,740 KB
testcase_28 AC 175 ms
5,268 KB
testcase_29 AC 171 ms
5,280 KB
testcase_30 AC 176 ms
5,436 KB
testcase_31 AC 174 ms
5,220 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 36 ms
4,380 KB
testcase_35 AC 343 ms
7,016 KB
testcase_36 AC 351 ms
7,008 KB
testcase_37 AC 352 ms
7,008 KB
testcase_38 AC 350 ms
7,176 KB
testcase_39 AC 374 ms
7,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 222;
const int MAX_M = 2222;

int N, M;
long long U[MAX_N];
vector<pair<int, int>> G[MAX_N];
long long dp[MAX_N][MAX_M];

void dfs(int now, int prev) {
    for (int i = 0; i <= M; i++) {
        dp[now][i] = U[now];
    }
    for (auto &&el : G[now]) {
        if (el.first != prev) {
            dfs(el.first, now);
            for (int i = M; i >= 0; i--) {
                for (int j = 0; j <= M; j++) {
                    if (i - j - el.second * 2 < 0) break;
                    dp[now][i] = max(dp[now][i], dp[now][i - j - el.second * 2] + dp[el.first][j]);
                }
            }
        }
    }
}

int main() {
    scanf("%d%d", &N, &M);
    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);
        //a--;b--;
        G[a].emplace_back(make_pair(b, c));
        G[b].emplace_back(make_pair(a, c));
    }
    dfs(0, -1);
    long long ans = 0;
    for (int i = 0; i <= M; i++) {
        ans = max(ans, dp[0][i]);
    }
    printf("%lld\n", ans);
}
0