結果
| 問題 |
No.417 チューリップバブル
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2016-08-27 09:47:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 1,645 bytes |
| コンパイル時間 | 1,766 ms |
| コンパイル使用メモリ | 102,280 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 18:59:16 |
| 合計ジャッジ時間 | 3,118 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 = 1010;
int N, M;
ll U[MAXN];
struct Edge {
int to;
int cost;
Edge() {}
Edge(int t, int c) : to(t), cost(c) {}
};
vector<Edge> G[MAXN];
ll dp[MAXN][MAXM];
void dfs(int v, int p) {
for (Edge e : G[v]) if (e.to != p) {
dfs(e.to, v);
}
for (Edge e : G[v]) if (e.to != p) {
for (int i = M; i >= 0; i--) {
for (int j = e.cost; j <= i; j++) {
dp[v][i] = max(dp[v][i], dp[v][i-j] + dp[e.to][j-e.cost]);
}
}
}
for (int i = 0; i <= M; i++)
dp[v][i] += U[v];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
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;
G[a].emplace_back(b, c);
G[b].emplace_back(a, c);
}
dfs(0, -1);
ll ans = 0;
for (int i = 0; i <= M; i++)
ans = max(ans, dp[0][i]);
cout << ans << endl;
return 0;
}
mayoko_