結果

問題 No.417 チューリップバブル
ユーザー latte0119latte0119
提出日時 2016-08-26 22:55:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 508 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 146,708 KB
実行使用メモリ 6,812 KB
最終ジャッジ日時 2023-08-08 03:54:20
合計ジャッジ時間 7,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 67 ms
4,380 KB
testcase_12 AC 67 ms
4,376 KB
testcase_13 AC 27 ms
4,376 KB
testcase_14 AC 109 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 60 ms
4,644 KB
testcase_18 AC 60 ms
4,728 KB
testcase_19 AC 59 ms
4,704 KB
testcase_20 AC 235 ms
5,368 KB
testcase_21 AC 231 ms
5,100 KB
testcase_22 AC 231 ms
5,112 KB
testcase_23 AC 230 ms
5,164 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 230 ms
5,248 KB
testcase_26 AC 22 ms
4,380 KB
testcase_27 AC 160 ms
4,624 KB
testcase_28 AC 227 ms
5,164 KB
testcase_29 AC 229 ms
5,100 KB
testcase_30 AC 233 ms
5,380 KB
testcase_31 AC 228 ms
5,108 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 46 ms
4,380 KB
testcase_35 AC 473 ms
6,596 KB
testcase_36 AC 463 ms
6,716 KB
testcase_37 AC 508 ms
6,728 KB
testcase_38 AC 479 ms
6,684 KB
testcase_39 AC 458 ms
6,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int N,M;
int U[200];
vector<edge>G[200];
int dp[200][2001];
void dfs(int v,int p){
    rep(i,M+1)dp[v][i]=U[v];
    for(auto e:G[v]){
        if(e.to==p)continue;
        dfs(e.to,v);
        for(int i=M;i-e.cost*2>=0;i--){
            for(int j=0;j+e.cost*2<=i;j++){
                chmax(dp[v][i],dp[v][i-j-e.cost*2]+dp[e.to][j]);
            }
        }
    }
}
signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,N)scanf("%lld",&U[i]);
    rep(i,N-1){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        G[a].pb(edge(b,c));
        G[b].pb(edge(a,c));
    }

    dfs(0,-1);
    printf("%lld\n",dp[0][M]);
    return 0;
}
0