結果

問題 No.417 チューリップバブル
ユーザー sekiya9311sekiya9311
提出日時 2018-03-31 07:51:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,190 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 168,668 KB
実行使用メモリ 7,108 KB
最終ジャッジ日時 2023-09-08 07:58:36
合計ジャッジ時間 16,671 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 31 ms
4,376 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 180 ms
4,376 KB
testcase_12 AC 180 ms
4,376 KB
testcase_13 AC 69 ms
4,376 KB
testcase_14 AC 285 ms
4,420 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 148 ms
4,688 KB
testcase_18 AC 148 ms
4,736 KB
testcase_19 AC 148 ms
4,684 KB
testcase_20 AC 585 ms
5,240 KB
testcase_21 AC 582 ms
5,264 KB
testcase_22 AC 585 ms
5,232 KB
testcase_23 AC 583 ms
5,240 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 585 ms
5,156 KB
testcase_26 AC 51 ms
4,376 KB
testcase_27 AC 410 ms
4,764 KB
testcase_28 AC 582 ms
5,160 KB
testcase_29 AC 581 ms
5,496 KB
testcase_30 AC 581 ms
5,192 KB
testcase_31 AC 581 ms
5,184 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 20 ms
4,380 KB
testcase_34 AC 205 ms
4,376 KB
testcase_35 AC 1,181 ms
7,108 KB
testcase_36 AC 1,180 ms
7,104 KB
testcase_37 AC 1,187 ms
6,956 KB
testcase_38 AC 1,190 ms
6,980 KB
testcase_39 AC 1,188 ms
6,996 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) continue;
                    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