結果

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

コンパイルメッセージ
main.cpp:16:13: error: 'uint32_t' does not name a type
   16 | using u32 = uint32_t;
      |             ^~~~~~~~
main.cpp:12:1: note: 'uint32_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
   11 | #include <limits>
  +++ |+#include <cstdint>
   12 | 
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/13.2.0/include/c++/13/string:48,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ios:44,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ostream:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/iostream:41,
                 from main.cpp:1

ソースコード

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[par][j-w[i]], dp[i][j-w[i]]+v[i]});
        }
    };
    dfs(0, 0, dfs);
    cout << *max_element(dp.front().begin(),dp.front().end()) << "\n";
    return 0;
}
0