結果
問題 |
No.417 チューリップバブル
|
ユーザー |
![]() |
提出日時 | 2020-03-31 11:50:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 720 ms / 2,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 1,981 ms |
コンパイル使用メモリ | 170,528 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 07:37:57 |
合計ジャッジ時間 | 11,155 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; using namespace std; int N, M; ll dp[201][2010]; ll U[201]; struct edge { int to, cost; edge(int t=0, int c=0) : to(t), cost(c) {} }; vector<edge> g[201]; void solve(int v, int p=-1) { dp[v][0] = U[v]; for (auto e : g[v]) { int u = e.to; if (u == p) continue; solve(u, v); for (int i = M; i >= 0; --i) { for (int j = 0; j <= M; ++j) { int tm = i + e.cost + j; if (tm <= M) dp[v][tm] = max(dp[v][tm], dp[v][i] + dp[u][j]); } } } } // // void solve(int v, int tm, int p=-1) { // dp[v][tm] = U[v]; // for (auto e : g[v]) { // if (e.to == p) continue; // int u = e.to; // if (tm + e.cost <= M) { // solve(u, tm + e.cost, v); // } // // for (int t = tm + 1; t <= M-e.cost; ++t) { // if (t + e.cost <= M) { // dp[v][t + e.cost] = max(dp[v][t + e.cost], dp[u][t + e.cost] + dp[v][tm]); // } // else { // dp[v][t] = max(dp[v][t], dp[v][t-1]); // } // } // // } // } 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].emplace_back(b, c * 2); g[b].emplace_back(a, c * 2); } solve(0); ll ans = 0; rep(i, M+1) ans = max(ans, dp[0][i]); cout << ans << endl; }