結果

問題 No.417 チューリップバブル
ユーザー veqccveqcc
提出日時 2019-02-20 18:00:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 96,700 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 20:01:16
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 12 ms
5,376 KB
testcase_11 AC 47 ms
5,376 KB
testcase_12 AC 46 ms
5,376 KB
testcase_13 AC 18 ms
5,376 KB
testcase_14 AC 74 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 40 ms
5,376 KB
testcase_19 AC 40 ms
5,376 KB
testcase_20 AC 151 ms
5,376 KB
testcase_21 AC 150 ms
5,376 KB
testcase_22 AC 151 ms
5,376 KB
testcase_23 AC 150 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 151 ms
5,376 KB
testcase_26 AC 15 ms
5,376 KB
testcase_27 AC 105 ms
5,376 KB
testcase_28 AC 150 ms
5,376 KB
testcase_29 AC 149 ms
5,376 KB
testcase_30 AC 150 ms
5,376 KB
testcase_31 AC 150 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 31 ms
5,376 KB
testcase_35 AC 306 ms
5,376 KB
testcase_36 AC 306 ms
5,376 KB
testcase_37 AC 307 ms
5,376 KB
testcase_38 AC 308 ms
5,376 KB
testcase_39 AC 312 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
typedef pair<int, int> P;

int n, m, u[205], a, b, c;
vector <P> edge[205];
int dp[205][2005]; // iを頂点とする部分木で、時間jで取ってこられる最大値

void dfs(int i, int par) {
    for (int j = 0; j <= m; j++) {
        dp[i][j] = u[i];
    }

    for (auto j : edge[i]) {
        int to = j.first;
        int cost = j.second * 2;
        if (to == par) continue;

        dfs(to, i);

        for (int k = m; k >= 0; k--) {
            for (int l = 0; l <= k - cost; l++) {
                dp[i][k] = max(dp[i][k], dp[to][l] + dp[i][k - l - cost]);
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> u[i];
    }

    for (int i = 1; i < n; i++) {
        cin >> a >> b >> c;
        edge[a].push_back(P(b, c));
        edge[b].push_back(P(a, c));
    }

    dfs(0, -1);

    cout << dp[0][m] << "\n";
    return 0;
}
0