結果
問題 | No.417 チューリップバブル |
ユーザー |
![]() |
提出日時 | 2018-05-17 14:00:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 730 ms / 2,000 ms |
コード長 | 1,558 bytes |
コンパイル時間 | 1,765 ms |
コンパイル使用メモリ | 175,256 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 13:28:24 |
合計ジャッジ時間 | 11,262 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>#define int long longusing namespace std;using LL = long long;using P = pair<int, int>;#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)#define REP(i, n) FOR(i, 0, n)#define pb(a) push_back(a)#define all(x) (x).begin(),(x).end()const int INF = (int)1e9;const LL INFL = (LL)1e15;const int MOD = 1e9 + 7;int dy[]={0, 0, 1, -1, 0};int dx[]={1, -1, 0, 0, 0};template <typename T>struct Edge{int to; T cost;Edge(int to, T cost) : to(to), cost(cost) {}};template <typename T>using Edges = vector<Edge<T>>;template <typename T>using AdjList = vector<Edges<T>>;/*************** using variables **************/AdjList<int> adj;int dp[205][2005];int n, m;vector<int> u;/**********************************************/void dfs(int cur, int pre){dp[cur][0] = u[cur];for(auto child: adj[cur]) if(child.to != pre){dfs(child.to, cur);for(int i = m; i >= 0; i--){REP(j, m+1){int t = i + child.cost * 2 + j;if(t <= m) dp[cur][t] = max(dp[cur][t], dp[cur][i] + dp[child.to][j]);}}}}signed main(){cin.tie(0);ios::sync_with_stdio(false);cin >> n >> m;u.resize(n);REP(i, n) cin >> u[i];adj.resize(n);REP(i, n-1){int a, b, c;cin >> a >> b >> c;adj[a].pb(Edge<int>(b, c));adj[b].pb(Edge<int>(a, c));}dfs(0, -1);int ans = 0;REP(i, m+1) ans = max(ans, dp[0][i]);cout << ans << endl;}