結果

問題 No.417 チューリップバブル
ユーザー momoyuumomoyuu
提出日時 2023-03-23 16:54:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,841 ms
コンパイル使用メモリ 252,008 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 19:34:25
合計ジャッジ時間 9,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 13 ms
4,348 KB
testcase_10 AC 17 ms
4,348 KB
testcase_11 AC 73 ms
4,348 KB
testcase_12 AC 72 ms
4,348 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 117 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 62 ms
4,348 KB
testcase_18 AC 63 ms
4,348 KB
testcase_19 AC 63 ms
4,348 KB
testcase_20 AC 244 ms
4,348 KB
testcase_21 AC 241 ms
4,348 KB
testcase_22 AC 241 ms
4,348 KB
testcase_23 AC 241 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 243 ms
4,348 KB
testcase_26 AC 23 ms
4,348 KB
testcase_27 AC 168 ms
4,348 KB
testcase_28 AC 241 ms
4,348 KB
testcase_29 AC 240 ms
4,348 KB
testcase_30 AC 240 ms
4,348 KB
testcase_31 AC 239 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 7 ms
4,348 KB
testcase_34 AC 49 ms
4,348 KB
testcase_35 AC 491 ms
4,348 KB
testcase_36 AC 490 ms
4,348 KB
testcase_37 AC 499 ms
4,348 KB
testcase_38 AC 494 ms
4,348 KB
testcase_39 AC 497 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n,m;
vector<pair<int,int> > g[210];
ll u[210];

vector<ll> dfs(int ni,int p){
    vector<ll> dp(m+1,u[ni]);
    for(auto&itr:g[ni])if(itr.first!=p){
        vector<ll> nxt = dfs(itr.first,ni);
        vector<ll> dp1(m+1,0);
        for(int i = 0;i<=m;i++) dp1[i] = dp[i];
        for(int i = 0;i<=m;i++){
            for(int j = 0;j<=i;j++){
                int rest = i - j - 2 * itr.second;
                if(rest<0) break;
                dp1[i] = max(dp1[i],max(dp[i],dp[j]+nxt[rest]));
            }
        }
        for(int i = 1;i<=m;i++) dp1[i] = max(dp1[i],dp1[i-1]);
        swap(dp,dp1);
    }
    return dp;
}


int main(){
    cin>>n>>m;
    for(int i = 0;i<n;i++) cin>>u[i];
    for(int i = 1;i<n;i++){
        int u,v,c;
        cin>>u>>v>>c;
        g[u].push_back(make_pair(v,c));
        g[v].push_back(make_pair(u,c));
    }
    vector<ll> ans = dfs(0,-1);
    cout<<ans[m]<<endl;
}

0