結果
| 問題 |
No.417 チューリップバブル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-15 17:48:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,793 bytes |
| コンパイル時間 | 714 ms |
| コンパイル使用メモリ | 93,200 KB |
| 最終ジャッジ日時 | 2024-11-14 21:50:25 |
| 合計ジャッジ時間 | 1,284 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:45: error: too many initializers for 'std::array<int, 2>'
39 | G[a].emplace_back(array<int, 2>{b, c});
| ^
main.cpp:40:45: error: too many initializers for 'std::array<int, 2>'
40 | G[b].emplace_back(array<int, 2>{a, c});
| ^
main.cpp: In lambda function:
main.cpp:52:17: error: no match for 'operator[]' (operand types are 'std::array<int, 2>' and 'int')
52 | if(j[0] != par) {
| ^
main.cpp:53:20: error: no match for 'operator[]' (operand types are 'std::array<int, 2>' and 'int')
53 | w[j[0]] = j[1];
| ^
main.cpp:53:28: error: no match for 'operator[]' (operand types are 'std::array<int, 2>' and 'int')
53 | w[j[0]] = j[1];
| ^
main.cpp:54:20: error: no match for 'operator[]' (operand types are 'std::array<int, 2>' and 'int')
54 | f(j[0], i, f);
| ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:47,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_iterator.h: In instantiation of '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++() [with _Iterator = std::array<int, 2>*;
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }
template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }
template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
int main() {
int n, m;
cin >> n >> m;
m /= 2;
vector<int> v(n);
for (auto &&i : v) scanf("%d", &i);
vector<vector<array<int, 2>>> G(n);
for (int i = 0; i < n - 1; ++i) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
G[a].emplace_back(array<int, 2>{b, c});
G[b].emplace_back(array<int, 2>{a, c});
}
vector<int> w(n);
auto dp = make_v(n, m+1, -INF<int>);
for (int i = 0; i < n; ++i) {
dp[i][0] = 0;
}
auto dfs = [&](int i, int par, auto &&f) -> void {
for (int j = 0; j <= m; ++j) {
dp[i][j] = dp[par][j];
}
for (auto &&j : G[i]) {
if(j[0] != par) {
w[j[0]] = j[1];
f(j[0], i, f);
}
}
for (int j = w[i]; j <= m; ++j) {
dp[par][j] = max(dp[par][j], dp[i][j-w[i]]+v[i]);
}
};
dfs(0, 0, dfs);
cout << *max_element(dp.front().begin(),dp.front().end()) << "\n";
return 0;
}