結果

問題 No.417 チューリップバブル
ユーザー iqueue02iqueue02
提出日時 2020-03-25 09:46:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 903 ms / 2,000 ms
コード長 980 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 178,440 KB
実行使用メモリ 6,312 KB
最終ジャッジ日時 2023-08-30 09:27:29
合計ジャッジ時間 14,113 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 39 ms
4,376 KB
testcase_11 AC 150 ms
4,376 KB
testcase_12 AC 146 ms
4,376 KB
testcase_13 AC 59 ms
4,376 KB
testcase_14 AC 229 ms
4,376 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 AC 103 ms
4,380 KB
testcase_18 AC 109 ms
4,380 KB
testcase_19 AC 116 ms
4,380 KB
testcase_20 AC 447 ms
4,620 KB
testcase_21 AC 432 ms
4,684 KB
testcase_22 AC 393 ms
4,916 KB
testcase_23 AC 435 ms
4,628 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 418 ms
4,696 KB
testcase_26 AC 41 ms
4,376 KB
testcase_27 AC 306 ms
4,380 KB
testcase_28 AC 430 ms
4,616 KB
testcase_29 AC 416 ms
4,576 KB
testcase_30 AC 415 ms
4,700 KB
testcase_31 AC 471 ms
4,704 KB
testcase_32 AC 5 ms
4,376 KB
testcase_33 AC 16 ms
4,376 KB
testcase_34 AC 215 ms
4,380 KB
testcase_35 AC 871 ms
6,156 KB
testcase_36 AC 903 ms
6,288 KB
testcase_37 AC 874 ms
6,220 KB
testcase_38 AC 893 ms
6,312 KB
testcase_39 AC 875 ms
6,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> U(n);
  rep(i,n) cin >> U[i];
  vector<vector<P>> g(n);
  rep(i,n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].emplace_back(make_pair(b, c));
    g[b].emplace_back(make_pair(a, c));
  }

  vector<vector<ll>> dp(n, vector<ll>(m+1,0));

  auto dfs = [&](auto& f, int p, int u)->void{
    dp[u][0] = U[u];
    for (auto e : g[u]) {
      if (e.first == p) continue;
      int v = e.first, cost = e.second;
      f(f, u, v);
      
      for (int i = m; i >= 0; i--) {
        for (int j = 0; j <= m; j++) {
          int t = i + cost * 2 + j;
          if (t <= m) dp[u][t] = max(dp[u][t], dp[u][i] + dp[v][j]);
        }
      }
    }
  };

  dfs(dfs, -1, 0);

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