結果
問題 | No.417 チューリップバブル |
ユーザー |
![]() |
提出日時 | 2019-02-20 18:00:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 593 ms / 2,000 ms |
コード長 | 1,219 bytes |
コンパイル時間 | 883 ms |
コンパイル使用メモリ | 95,820 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 04:53:16 |
合計ジャッジ時間 | 8,612 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; typedef unsigned int uint; using namespace std; typedef pair<int, int> P; int n, m, u[205], a, b, c; vector <P> edge[205]; int dp[205][2005]; // iを頂点とする部分木で、時間jで取ってこられる最大値 void dfs(int i, int par) { for (int j = 0; j <= m; j++) { dp[i][j] = u[i]; } for (auto j : edge[i]) { int to = j.first; int cost = j.second * 2; if (to == par) continue; dfs(to, i); for (int k = m; k >= 0; k--) { for (int l = 0; l <= k - cost; l++) { dp[i][k] = max(dp[i][k], dp[to][l] + dp[i][k - l - cost]); } } } } int main() { cin.sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> u[i]; } for (int i = 1; i < n; i++) { cin >> a >> b >> c; edge[a].push_back(P(b, c)); edge[b].push_back(P(a, c)); } dfs(0, -1); cout << dp[0][m] << "\n"; return 0; }