結果

問題 No.417 チューリップバブル
ユーザー bonKotsubonKotsu
提出日時 2022-07-17 01:14:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 205,100 KB
実行使用メモリ 5,308 KB
最終ジャッジ日時 2023-09-11 11:36:55
合計ジャッジ時間 13,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,004 KB
testcase_01 AC 3 ms
5,020 KB
testcase_02 AC 3 ms
5,084 KB
testcase_03 AC 3 ms
5,064 KB
testcase_04 AC 3 ms
5,000 KB
testcase_05 AC 3 ms
5,020 KB
testcase_06 AC 3 ms
4,996 KB
testcase_07 AC 3 ms
5,304 KB
testcase_08 AC 12 ms
5,052 KB
testcase_09 AC 24 ms
4,992 KB
testcase_10 AC 33 ms
5,064 KB
testcase_11 AC 124 ms
4,984 KB
testcase_12 AC 126 ms
5,076 KB
testcase_13 AC 51 ms
5,052 KB
testcase_14 AC 196 ms
5,020 KB
testcase_15 AC 16 ms
5,088 KB
testcase_16 AC 16 ms
5,020 KB
testcase_17 AC 102 ms
4,980 KB
testcase_18 AC 102 ms
5,020 KB
testcase_19 AC 102 ms
5,308 KB
testcase_20 AC 396 ms
5,084 KB
testcase_21 AC 394 ms
5,128 KB
testcase_22 AC 397 ms
4,996 KB
testcase_23 AC 396 ms
5,192 KB
testcase_24 AC 3 ms
5,064 KB
testcase_25 AC 397 ms
4,992 KB
testcase_26 AC 37 ms
5,052 KB
testcase_27 AC 278 ms
4,988 KB
testcase_28 AC 394 ms
5,080 KB
testcase_29 AC 394 ms
5,084 KB
testcase_30 AC 397 ms
5,000 KB
testcase_31 AC 394 ms
5,188 KB
testcase_32 AC 6 ms
5,004 KB
testcase_33 AC 17 ms
5,000 KB
testcase_34 AC 170 ms
4,996 KB
testcase_35 AC 796 ms
5,168 KB
testcase_36 AC 794 ms
5,008 KB
testcase_37 AC 795 ms
4,976 KB
testcase_38 AC 796 ms
5,204 KB
testcase_39 AC 797 ms
5,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };
int n, m;
vector<int> u(210);
vector dp(210, vector<int>(2005));

struct Edge {
  int to, c;
  Edge(int to, int c) : to(to), c(c) {}
};

vector<Edge> g[210];

void dfs(int v, int p = -1) {
  dp[v][0] = u[v];
  for (auto e : g[v]) {
    int nv = e.to, c = e.c;
    if (nv == p) continue;
    dfs(nv, v);
    for (int i = m; i >= 0; i--) { 
      for (int j = m; j >= 0; j--) {
        if (i+j+2*c <= m) {
          chmax(dp[v][i+j+2*c],dp[v][i]+dp[nv][j]);
        }
      }
    }
  }
}

int main() {
  cin >> n >> m;
  rep(i,n) cin >> u[i];
  rep(i,n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].pb(Edge(b,c));
    g[b].pb(Edge(a,c));
  }
  dfs(0);
  int ans = 0;
  rep(i,m+1) chmax(ans, dp[0][i]);
  cout << ans << endl;

  return 0;
}
0