結果
問題 | No.417 チューリップバブル |
ユーザー |
![]() |
提出日時 | 2016-08-27 00:11:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 889 ms / 2,000 ms |
コード長 | 1,741 bytes |
コンパイル時間 | 1,112 ms |
コンパイル使用メモリ | 105,824 KB |
実行使用メモリ | 16,640 KB |
最終ジャッジ日時 | 2024-11-08 16:49:56 |
合計ジャッジ時間 | 10,777 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>//#include<cctype>#include<climits>#include<iostream>#include<string>#include<vector>#include<map>//#include<list>#include<queue>#include<deque>#include<algorithm>//#include<numeric>#include<utility>//#include<memory>#include<functional>#include<cassert>#include<set>#include<stack>#include<random>const int dx[] = {1, 0, -1, 0};const int dy[] = {0, -1, 0, 1};using namespace std;typedef long long ll;typedef unsigned long long ull;typedef vector<int> vi;typedef vector<ll> vll;typedef pair<int, int> pii;const int MAXN = 222;const int MAXM = 1101;ll U[MAXN];struct Edge {int to;int cost;Edge() {}Edge(int t, int c) : to(t), cost(c) {}};vector<Edge> es[MAXN];vector<ll> dp[MAXN][MAXM];ll dfs(int v, int rest, int now, int p) {ll& ret = dp[v][rest][now];if (ret >= 0) return ret;if (now == es[v].size()) return ret = U[v];ret = dfs(v, rest, now+1, p);Edge e = es[v][now];if (e.to != p && e.cost <= rest) {for (int i = 0; i <= rest-e.cost; i++) {ret = max(ret, dfs(e.to, i, 0, v) + dfs(v, rest-e.cost-i, now+1, p));}}return ret;}int main() {cin.tie(0);ios::sync_with_stdio(false);int N, M;cin >> N >> M;M /= 2;for (int i = 0; i < N; i++)cin >> U[i];for (int i = 0; i < N-1; i++) {int a, b, c;cin >> a >> b >> c;es[a].emplace_back(b, c);es[b].emplace_back(a, c);}for (int i = 0; i < N; i++) {for (int j = 0; j <= M; j++) {dp[i][j].resize(es[i].size()+1, -1);}}cout << dfs(0, M, 0, -1) << endl;return 0;}