結果
問題 |
No.417 チューリップバブル
|
ユーザー |
![]() |
提出日時 | 2022-05-27 00:07:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,124 bytes |
コンパイル時間 | 2,244 ms |
コンパイル使用メモリ | 187,604 KB |
実行使用メモリ | 16,416 KB |
最終ジャッジ日時 | 2024-09-20 15:09:24 |
合計ジャッジ時間 | 24,825 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 TLE * 1 -- * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<long long> U; struct Edge{ int to,w; Edge(int a,int b){ to = a; w = b; } Edge(){} }; vector<vector<Edge>> G; vector<vector<vector<long long>>> memo; long long DFS(int v,int a,int t,int p = -1){ if(a<0) return 0; if(G[v][a].to==p) return DFS(v,a-1,t,p); if(memo[v][a][t]!=-1) return memo[v][a][t]; long long res = DFS(v,a-1,t,p); for(int j = 0;j <= (t-2*G[v][a].w);j++){ res = max(res,DFS(v,a-1,t-2*G[v][a].w-j,p)+DFS(G[v][a].to,(int)G[G[v][a].to].size()-1,j,v)+U[G[v][a].to]); } memo[v][a][t] = res; return res; } int main(){ int N,M; cin >> N >> M; U.assign(N,0); for(int i = 0;i < N;i++) cin >> U[i]; G.assign(N,vector<Edge>(0)); for(int i = 0;i < N-1;i++){ int A,B,C; cin >> A >> B >> C; G[A].push_back(Edge(B,C)); G[B].push_back(Edge(A,C)); } memo.assign(N,vector<vector<long long>>(0)); for(int i = 0;i < N;i++) memo[i].assign(G[i].size(),vector<long long>(M+1,-1)); cout << DFS(0,(int)G[0].size()-1,M)+U[0] << endl; }