結果
問題 | No.417 チューリップバブル |
ユーザー | tubo28 |
提出日時 | 2016-08-26 23:55:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 520 ms / 2,000 ms |
コード長 | 1,782 bytes |
コンパイル時間 | 1,237 ms |
コンパイル使用メモリ | 118,876 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 16:38:20 |
合計ジャッジ時間 | 7,631 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; using ll = long long; int n, tl; int u[222]; struct edge { int s, d, w; }; vector<vector<edge>> g; int mem[201 * 2001]; int ofs = 0; int *fetch(int sz) { int *res = mem + ofs; ofs += sz; return res; } int *solve(int v, int tl, int p) { int *res = fetch(tl + 1); fill(res, res + tl + 1, u[v]); for (auto &e : g[v]) { if (e.d == p) continue; if (tl < e.w * 2) continue; int *cdp = solve(e.d, tl - e.w*2, v); for (int i = tl; i >= 0; --i) { for (int j = 0; j <= i - e.w * 2; ++j) { res[i] = max(res[i], res[i - j - 2 * e.w] + cdp[j]); } } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(0); while (cin >> n >> tl) { for (int i = 0; i < n; i++) { cin >> u[i]; } g.assign(n, {}); for (int i = 1; i < n; i++) { int a, b, e; cin >> a >> b >> e; g[a].push_back({ a,b,e }); g[b].push_back({ b,a,e }); } int *a = solve(0, tl, -1); cout << a[tl] << endl; } }