結果
| 問題 |
No.417 チューリップバブル
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-04-22 21:07:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,077 ms / 2,000 ms |
| コード長 | 1,159 bytes |
| コンパイル時間 | 4,295 ms |
| コンパイル使用メモリ | 284,076 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-22 21:07:22 |
| 合計ジャッジ時間 | 16,913 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#define int long long
//#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME "tulip"
using namespace std;
constexpr int N = 2e2 + 5,M = 2e3 + 5;
vector<pair<int,int> > G[N];
int c[N],f[N][M];
void solve() {
int n,m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i < n; i++) {
int u,v,w;
cin >> u >> v >> w;
u++,v++;
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
auto dfs = [&](auto&& dfs,int x,int fa) -> void {
f[x][0] = c[x];
for (auto it : G[x]) {
int v = it.first,w = it.second;
if (v == fa) continue;
dfs(dfs,v,x);
for (int i = m; i >= 0; i--) {
for (int j = 0; j <= m; j++) {
int t = i + 2 * w + j;
if (t <= m) f[x][t] = max(f[x][t],f[x][i] + f[v][j]);
}
}
}
};
dfs(dfs,1,0);
cout << *max_element(f[1],f[1] + m + 1) << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#ifdef USE_FREOPEN
freopen(FILENAME ".in","r",stdin);
freopen(FILENAME ".out","w",stdout);
#endif
int _ = 1;
#ifdef MUL_TEST
cin >> _;
#endif
while (_--)
solve();
_^=_;
return 0^_^0;
}
vjudge1