結果

問題 No.417 チューリップバブル
ユーザー hashiryohashiryo
提出日時 2018-12-20 16:59:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,646 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 102,876 KB
実行使用メモリ 6,904 KB
最終ジャッジ日時 2023-10-26 01:05:22
合計ジャッジ時間 6,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,348 KB
testcase_09 AC 10 ms
4,348 KB
testcase_10 AC 13 ms
4,348 KB
testcase_11 AC 50 ms
4,348 KB
testcase_12 AC 49 ms
4,348 KB
testcase_13 AC 19 ms
6,136 KB
testcase_14 AC 77 ms
6,328 KB
testcase_15 AC 8 ms
5,976 KB
testcase_16 AC 7 ms
5,976 KB
testcase_17 AC 42 ms
6,140 KB
testcase_18 AC 43 ms
6,140 KB
testcase_19 AC 42 ms
6,140 KB
testcase_20 AC 158 ms
6,332 KB
testcase_21 AC 157 ms
6,332 KB
testcase_22 AC 158 ms
6,332 KB
testcase_23 AC 159 ms
6,332 KB
testcase_24 AC 2 ms
5,824 KB
testcase_25 AC 158 ms
6,332 KB
testcase_26 AC 16 ms
6,040 KB
testcase_27 AC 111 ms
6,332 KB
testcase_28 AC 157 ms
6,332 KB
testcase_29 AC 157 ms
6,332 KB
testcase_30 AC 157 ms
6,332 KB
testcase_31 AC 157 ms
6,332 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 34 ms
6,328 KB
testcase_35 AC 321 ms
6,904 KB
testcase_36 AC 320 ms
6,904 KB
testcase_37 AC 322 ms
6,904 KB
testcase_38 AC 323 ms
6,904 KB
testcase_39 AC 324 ms
6,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

struct Edge{
  int src,dst;
  ll weight;
  Edge(int a,int b,ll c):src(a),dst(b),weight(c){}
};

int N,M;
ll U[210];
vector<vector<Edge> > G;
ll dp[210][2100];

void dfs(int v,int par){
  repeat(i,M+1){
    dp[v][i]=U[v];
  }
  for(Edge e:G[v])if(e.dst!=par){
    dfs(e.dst,v);
    for(int m=M;m>=0;m--){
      repeat(i,m-2*e.weight+1){
        dp[v][m]=max(dp[v][m],dp[v][m-i-2*e.weight]+dp[e.dst][i]);
      }
    }
  }
  //debug(v);
  //debugArray(dp[v],M+1);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  G.resize(N);
  repeat(i,N){
    cin >> U[i];
  }
  //debugArray(U,N);
  repeat(i,N-1){
    int a,b;ll c;
    cin >> a >> b >> c;
    G[a].push_back({a,b,c});
    G[b].push_back({b,a,c});
  }
  dfs(0,-1);
  cout << dp[0][M] << endl;
  return 0;
}
0