結果
| 問題 |
No.417 チューリップバブル
|
| ユーザー |
|
| 提出日時 | 2021-11-04 22:49:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,213 ms / 2,000 ms |
| コード長 | 1,370 bytes |
| コンパイル時間 | 2,586 ms |
| コンパイル使用メモリ | 200,288 KB |
| 最終ジャッジ日時 | 2025-01-25 11:48:37 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
コンパイルメッセージ
main.cpp:20:26: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
20 | void dfs(int v, int par, auto& dp, auto& U){
| ^~~~
main.cpp:20:36: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
20 | void dfs(int v, int par, auto& dp, auto& U){
| ^~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
using P = pair<ll, ll>;
vector<P> G[210];
ll N, M;
void dfs(int v, int par, auto& dp, auto& U){
dp[v][0] = U[v];
for(auto& [nv, cost] : G[v]) {
if(par == nv) continue;
dfs(nv, v, dp, U);
for(int m0 = M-1; m0 >= 0; m0--){
for(int m1 = M-1; m1 >= 0; m1--){
auto nm = m0 + m1 + 2*cost;
if(nm <= M)
chmax(dp[v][nm], dp[v][m0] + dp[nv][m1]);
}
}
}
}
int main(){
cin >> N >> M;
vector<ll> U(N);
for(auto& u : U)
cin >> u;
REP(i,N-1){
ll a, b, c;
cin >> a >> b >> c;
G[a].push_back(P(b, c));
G[b].push_back(P(a, c));
}
vector<vector<ll>> dp(N, vector<ll>(M+1, 0));
dfs(0, -1, dp, U);
ll ans = 0;
REP(m,M+1)
chmax(ans, dp[0][m]);
cout << ans << endl;
return 0;
}