結果

問題 No.417 チューリップバブル
ユーザー nxterunxteru
提出日時 2018-07-02 23:11:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 73,968 KB
実行使用メモリ 4,728 KB
最終ジャッジ日時 2023-09-13 17:05:15
合計ジャッジ時間 6,536 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 60 ms
4,376 KB
testcase_12 AC 60 ms
4,376 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 96 ms
4,376 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 51 ms
4,380 KB
testcase_18 AC 51 ms
4,376 KB
testcase_19 AC 52 ms
4,380 KB
testcase_20 AC 199 ms
4,376 KB
testcase_21 AC 197 ms
4,376 KB
testcase_22 AC 197 ms
4,380 KB
testcase_23 AC 198 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 198 ms
4,380 KB
testcase_26 AC 19 ms
4,380 KB
testcase_27 AC 138 ms
4,380 KB
testcase_28 AC 196 ms
4,376 KB
testcase_29 AC 196 ms
4,376 KB
testcase_30 AC 198 ms
4,380 KB
testcase_31 AC 196 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 41 ms
4,376 KB
testcase_35 AC 402 ms
4,524 KB
testcase_36 AC 401 ms
4,520 KB
testcase_37 AC 404 ms
4,728 KB
testcase_38 AC 405 ms
4,616 KB
testcase_39 AC 412 ms
4,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
int n,m,w[205],dp[205][2005];
vector<P>g[205];
void dfs(int v,int p){
    for(int k=0;k<g[v].size();k++){
        int u=g[v][k].F,d=g[v][k].S*2;
        if(u!=p){
            dfs(u,v);
            int q[2005]={};
            for(int i=0;i+d<=m;i++){
                for(int j=0;i+j+d<=m;j++){
                    q[i+j+d]=max(q[i+j+d],dp[u][i]+dp[v][j]+w[u]);
                }
            }
            for(int i=0;i<=m;i++)dp[v][i]=max(dp[v][i],q[i]);
        }
    }
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>w[i];
    for(int i=0;i<n-1;i++){
        int a,b,x;
        cin>>a>>b>>x;
        g[a].push_back(P(b,x));
        g[b].push_back(P(a,x));
    }
    dfs(0,-1);
    int ans=0;
    for(int i=m;i>=0;i--)ans=max(ans,dp[0][i]);
    cout<<ans+w[0]<<endl;
}
0