結果
| 問題 |
No.417 チューリップバブル
|
| ユーザー |
|
| 提出日時 | 2016-08-26 23:03:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 2,000 ms |
| コード長 | 993 bytes |
| コンパイル時間 | 1,762 ms |
| コンパイル使用メモリ | 161,752 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 09:43:53 |
| 合計ジャッジ時間 | 4,613 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%lld", &u[i]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct edge {
int next;
long long cost;
};
const long long inf = 1e17;
int n, m;
vector<edge> g[200];
long long u[200];
long long dp[222][1010];
void chmax(long long &a, long long b) {
if (a < b) a = b;
}
void dfs(int curr, int prev) {
for (int i = 0; i < 1010; i++) {
dp[curr][i] = -inf;
}
dp[curr][0] = u[curr];
for (edge e : g[curr]) if (e.next != prev) {
dfs(e.next, curr);
for (int i = 1000; i >= 0; i--) {
if (dp[curr][i] == inf) continue;
for (int j = 0; i + j + e.cost <= 1000; j++) {
chmax(dp[curr][i + j + e.cost], dp[curr][i] + dp[e.next][j]);
}
}
}
}
int main() {
cin >> n >> m;
m /= 2;
for (int i = 0; i < n; i++) {
scanf("%lld", &u[i]);
}
for (int i = 0; i < n - 1; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
g[a].push_back({ b, c });
g[b].push_back({ a, c });
}
dfs(0, -1);
long long ans = 0;
for (int i = 0; i <= m; i++) chmax(ans, dp[0][i]);
cout << ans << endl;
}