結果

問題 No.417 チューリップバブル
ユーザー tossytossy
提出日時 2016-08-28 14:56:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 95,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 16:56:47
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 15 ms
5,376 KB
testcase_10 AC 20 ms
5,376 KB
testcase_11 AC 86 ms
5,376 KB
testcase_12 AC 85 ms
5,376 KB
testcase_13 AC 33 ms
5,376 KB
testcase_14 AC 139 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 73 ms
5,376 KB
testcase_18 AC 70 ms
5,376 KB
testcase_19 AC 73 ms
5,376 KB
testcase_20 AC 286 ms
5,376 KB
testcase_21 AC 281 ms
5,376 KB
testcase_22 AC 288 ms
5,376 KB
testcase_23 AC 280 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 282 ms
5,376 KB
testcase_26 AC 26 ms
5,376 KB
testcase_27 AC 196 ms
5,376 KB
testcase_28 AC 275 ms
5,376 KB
testcase_29 AC 283 ms
5,376 KB
testcase_30 AC 275 ms
5,376 KB
testcase_31 AC 281 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 9 ms
5,376 KB
testcase_34 AC 57 ms
5,376 KB
testcase_35 AC 574 ms
5,376 KB
testcase_36 AC 562 ms
5,376 KB
testcase_37 AC 594 ms
5,376 KB
testcase_38 AC 584 ms
5,376 KB
testcase_39 AC 607 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 1e+9

typedef pair<int, int> P;
int u[210];
vector<vector<P> > vec;

int dp[205][2010];
int n,m;

void dfs(int from, int d){
  dp[d][0] = u[d];
  for(P p : vec[d]) if(p.fi!=from){
    int to = p.fi, cost = p.se;

    dfs(d, to);

    for(int i = m; i>=cost*2; i--){
      // update dp[d][i]
      for(int j=0; j+cost*2<=i; j++){
        // use dp[to][j]
        dp[d][i] = max(dp[d][i], dp[to][j] + dp[d][i-cost*2-j]);
      }
    }
  }
}

int main(){
  cin>>n>>m;
  rep(i,n) scanf("%d", &u[i]);

  vec =  vector<vector<P> >(n);
  // pair<to, cost>
  rep(i,n-1){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    vec[a].pb(mp(b,c));
    vec[b].pb(mp(a,c));
  }

  fill(dp[0], dp[n], -INF);
  dfs(-1,0);

  int res=0;
  rep(i,m+1) res = max(res, dp[0][i]);
  cout<<res<<endl;

  return 0;
}
0