結果

問題 No.417 チューリップバブル
ユーザー kura197kura197
提出日時 2021-12-31 23:03:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 886 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 204,920 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 11:37:03
合計ジャッジ時間 13,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 25 ms
6,944 KB
testcase_10 AC 35 ms
6,940 KB
testcase_11 AC 137 ms
6,944 KB
testcase_12 AC 136 ms
6,940 KB
testcase_13 AC 55 ms
6,940 KB
testcase_14 AC 217 ms
6,944 KB
testcase_15 AC 16 ms
6,940 KB
testcase_16 AC 16 ms
6,940 KB
testcase_17 AC 114 ms
6,940 KB
testcase_18 AC 113 ms
6,940 KB
testcase_19 AC 112 ms
6,940 KB
testcase_20 AC 440 ms
6,940 KB
testcase_21 AC 439 ms
6,944 KB
testcase_22 AC 437 ms
6,944 KB
testcase_23 AC 448 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 443 ms
6,944 KB
testcase_26 AC 41 ms
6,940 KB
testcase_27 AC 309 ms
6,944 KB
testcase_28 AC 438 ms
6,944 KB
testcase_29 AC 441 ms
6,944 KB
testcase_30 AC 444 ms
6,940 KB
testcase_31 AC 438 ms
6,944 KB
testcase_32 AC 5 ms
6,944 KB
testcase_33 AC 18 ms
6,940 KB
testcase_34 AC 179 ms
6,944 KB
testcase_35 AC 880 ms
6,940 KB
testcase_36 AC 886 ms
6,944 KB
testcase_37 AC 886 ms
6,940 KB
testcase_38 AC 885 ms
6,940 KB
testcase_39 AC 881 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

using P = pair<int, ll>;
int N, M;
vector<ll> U;
vector<P> G[210];

void dfs(int v, int p, vector<vector<ll>>& dp){
    REP(m, M+1) dp[v][m] = U[v];
    for(auto& [nv, c] : G[v]){
        if(nv == p) continue;
        dfs(nv, v, dp);
        for(int m0 = M; m0 >= 0; m0--){
            for(int m1 = M; m1 >= 0; m1--){
                if(m0 + m1 + 2*c <= M)
                    chmax(dp[v][m0 + m1 + 2*c], dp[v][m0] + dp[nv][m1]);
            }
        }
    }
}

int main(){
    cin >> N >> M;
    U.resize(N);
    for(auto& u : U) cin >> u;
    REP(i,N-1){
        ll a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    vector<vector<ll>> dp(N, vector<ll>(M+1));
    dfs(0, -1, dp);

    ll ans = 0;
    REP(m,M+1) chmax(ans, dp[0][m]);
    cout << ans << endl;
    return 0;
}
0