結果

問題 No.417 チューリップバブル
ユーザー firiexpfiriexp
提出日時 2019-11-15 17:48:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,793 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 90,420 KB
最終ジャッジ日時 2023-07-25 09:48:12
合計ジャッジ時間 1,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:39:45: エラー: too many initializers for ‘std::array<int, 2>’
   39 |         G[a].emplace_back(array<int, 2>{b, c});
      |                                             ^
main.cpp:40:45: エラー: too many initializers for ‘std::array<int, 2>’
   40 |         G[b].emplace_back(array<int, 2>{a, c});
      |                                             ^
main.cpp: ラムダ関数内:
main.cpp:52:17: エラー: no match for ‘operator[]’ (operand types are ‘std::array<int, 2>’ and ‘int’)
   52 |             if(j[0] != par) {
      |                 ^
main.cpp:53:20: エラー: no match for ‘operator[]’ (operand types are ‘std::array<int, 2>’ and ‘int’)
   53 |                 w[j[0]] = j[1];
      |                    ^
main.cpp:53:28: エラー: no match for ‘operator[]’ (operand types are ‘std::array<int, 2>’ and ‘int’)
   53 |                 w[j[0]] = j[1];
      |                            ^
main.cpp:54:20: エラー: no match for ‘operator[]’ (operand types are ‘std::array<int, 2>’ and ‘int’)
   54 |                 f(j[0], i, f);
      |                    ^
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/string:47,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/locale_classes.h:40,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:41,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:42,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ostream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/iostream:39,
         次から読み込み:  main.cpp:1:
/usr/local/gcc7/include/c++/12.2.0/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>*; _Container = std::vector<st

ソースコード

diff #

#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;
}
0