結果

問題 No.417 チューリップバブル
ユーザー pionepione
提出日時 2020-07-13 08:18:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,070 ms / 2,000 ms
コード長 2,276 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 170,660 KB
実行使用メモリ 5,664 KB
最終ジャッジ日時 2023-08-06 22:30:56
合計ジャッジ時間 15,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 AC 43 ms
4,376 KB
testcase_11 AC 165 ms
4,380 KB
testcase_12 AC 165 ms
4,376 KB
testcase_13 AC 66 ms
4,380 KB
testcase_14 AC 261 ms
4,376 KB
testcase_15 AC 19 ms
4,380 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 136 ms
4,376 KB
testcase_18 AC 136 ms
4,380 KB
testcase_19 AC 136 ms
4,376 KB
testcase_20 AC 530 ms
4,380 KB
testcase_21 AC 530 ms
4,376 KB
testcase_22 AC 529 ms
4,376 KB
testcase_23 AC 528 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 530 ms
4,416 KB
testcase_26 AC 48 ms
4,376 KB
testcase_27 AC 369 ms
4,376 KB
testcase_28 AC 528 ms
4,432 KB
testcase_29 AC 527 ms
4,424 KB
testcase_30 AC 529 ms
4,380 KB
testcase_31 AC 528 ms
4,380 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 22 ms
4,380 KB
testcase_34 AC 240 ms
4,376 KB
testcase_35 AC 1,063 ms
5,336 KB
testcase_36 AC 1,065 ms
5,200 KB
testcase_37 AC 1,070 ms
5,596 KB
testcase_38 AC 1,069 ms
5,664 KB
testcase_39 AC 1,066 ms
5,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m; 
struct edge{
  ll to, cost;
};
vector<edge> G[205];
ll dp[205][2005];
vll tax;

void dfs(ll v, ll p){
  for(auto &e: G[v]){
    if(e.to==p) continue;
    dfs(e.to, v);
    vll tmp(m+1);
    rep(i,m+1){
      rep(j,m+1){
        if(i+(e.cost*2)+j<=m) chmax(tmp[i+(e.cost*2)+j],dp[v][j]+dp[e.to][i]+tax[e.to]);
      }
    }
    rep(i,m+1) chmax(dp[v][i],tmp[i]);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n>>m;
  tax.resize(n);
  rep(i,n) cin>>tax[i];
  
  rep(i,n-1){
    ll a,b,c; cin>>a>>b>>c;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }
  
  dfs(0,-1);
  ll ans=0;
  rep(i,m+1){
    chmax(ans,dp[0][i]);
  }
  ans+=tax[0];
  cout<<ans<<endl;
}
0