結果

問題 No.417 チューリップバブル
ユーザー dsytk7dsytk7
提出日時 2020-03-31 11:50:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 724 ms / 2,000 ms
コード長 1,561 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 169,200 KB
実行使用メモリ 5,900 KB
最終ジャッジ日時 2023-09-06 13:01:29
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 21 ms
4,376 KB
testcase_10 AC 30 ms
4,380 KB
testcase_11 AC 113 ms
4,376 KB
testcase_12 AC 113 ms
4,380 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 180 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 93 ms
4,376 KB
testcase_18 AC 94 ms
4,376 KB
testcase_19 AC 94 ms
4,380 KB
testcase_20 AC 357 ms
4,380 KB
testcase_21 AC 332 ms
4,384 KB
testcase_22 AC 332 ms
4,484 KB
testcase_23 AC 342 ms
4,512 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 327 ms
4,568 KB
testcase_26 AC 30 ms
4,380 KB
testcase_27 AC 237 ms
4,380 KB
testcase_28 AC 323 ms
4,380 KB
testcase_29 AC 325 ms
4,384 KB
testcase_30 AC 342 ms
4,380 KB
testcase_31 AC 330 ms
4,392 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 14 ms
4,380 KB
testcase_34 AC 155 ms
4,380 KB
testcase_35 AC 659 ms
5,448 KB
testcase_36 AC 681 ms
5,356 KB
testcase_37 AC 697 ms
5,900 KB
testcase_38 AC 724 ms
5,536 KB
testcase_39 AC 663 ms
5,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

int N, M;
ll dp[201][2010];
ll U[201];

struct edge {
    int to, cost;
    edge(int t=0, int c=0) : to(t), cost(c) {}
};
vector<edge> g[201];

void solve(int v, int p=-1) {
    dp[v][0] = U[v];

    for (auto e : g[v]) {
        int u = e.to;
        if (u == p) continue;
        solve(u, v);
        for (int i = M; i >= 0; --i) {
            for (int j = 0; j <= M; ++j) {
                int tm = i + e.cost + j;
                if (tm <= M) dp[v][tm] = max(dp[v][tm], dp[v][i] + dp[u][j]);
            }
        }
    }
}

//
// void solve(int v, int tm, int p=-1) {
//     dp[v][tm] = U[v];
//     for (auto e : g[v]) {
//         if (e.to == p) continue;
//         int u = e.to;
//         if (tm + e.cost <= M) {
//             solve(u, tm + e.cost, v);
//         }
//
//         for (int t = tm + 1; t <= M-e.cost; ++t) {
//             if (t + e.cost <= M) {
//                 dp[v][t + e.cost] = max(dp[v][t + e.cost], dp[u][t + e.cost] + dp[v][tm]);
//             }
//             else {
//                 dp[v][t] = max(dp[v][t], dp[v][t-1]);
//             }
//         }
//
//     }
// }

int main() {
    cin >> N >> M;
    rep(i, N) cin >> U[i];
    rep(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].emplace_back(b, c * 2);
        g[b].emplace_back(a, c * 2);
    }
    solve(0);
    ll ans = 0;
    rep(i, M+1) ans = max(ans, dp[0][i]);
    cout << ans << endl;


}
0