結果

問題 No.417 チューリップバブル
ユーザー kura197kura197
提出日時 2021-11-04 22:49:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,161 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 204,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 05:39:06
合計ジャッジ時間 16,130 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 15 ms
6,940 KB
testcase_09 AC 32 ms
6,940 KB
testcase_10 AC 46 ms
6,940 KB
testcase_11 AC 183 ms
6,940 KB
testcase_12 AC 179 ms
6,940 KB
testcase_13 AC 74 ms
6,944 KB
testcase_14 AC 278 ms
6,944 KB
testcase_15 AC 21 ms
6,940 KB
testcase_16 AC 21 ms
6,940 KB
testcase_17 AC 147 ms
6,944 KB
testcase_18 AC 151 ms
6,944 KB
testcase_19 AC 145 ms
6,940 KB
testcase_20 AC 570 ms
6,944 KB
testcase_21 AC 566 ms
6,944 KB
testcase_22 AC 564 ms
6,944 KB
testcase_23 AC 576 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 584 ms
6,944 KB
testcase_26 AC 56 ms
6,940 KB
testcase_27 AC 405 ms
6,940 KB
testcase_28 AC 577 ms
6,944 KB
testcase_29 AC 577 ms
6,944 KB
testcase_30 AC 575 ms
6,940 KB
testcase_31 AC 569 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 AC 21 ms
6,940 KB
testcase_34 AC 235 ms
6,940 KB
testcase_35 AC 1,145 ms
6,940 KB
testcase_36 AC 1,147 ms
6,940 KB
testcase_37 AC 1,161 ms
6,940 KB
testcase_38 AC 1,149 ms
6,944 KB
testcase_39 AC 1,124 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:26: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   20 | void dfs(int v, int par, auto& dp, auto& U){
      |                          ^~~~
main.cpp:20:36: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   20 | void dfs(int v, int par, auto& dp, auto& U){
      |                                    ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

using P = pair<ll, ll>;
vector<P> G[210];
ll N, M;

void dfs(int v, int par, auto& dp, auto& U){
    dp[v][0] = U[v];
    for(auto& [nv, cost] : G[v]) {
        if(par == nv) continue;
        dfs(nv, v, dp, U);
        for(int m0 = M-1; m0 >= 0; m0--){
            for(int m1 = M-1; m1 >= 0; m1--){
                auto nm = m0 + m1 + 2*cost;
                if(nm <= M)
                    chmax(dp[v][nm], dp[v][m0] + dp[nv][m1]);
            }
        }
    }
}

int main(){
    cin >> N >> M;
    vector<ll> U(N);
    for(auto& u : U)
        cin >> u;
    REP(i,N-1){
        ll a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(P(b, c));
        G[b].push_back(P(a, c));
    }
    
    vector<vector<ll>> dp(N, vector<ll>(M+1, 0));
    dfs(0, -1, dp, U);

    ll ans = 0;
    REP(m,M+1)
        chmax(ans, dp[0][m]);

    cout << ans << endl;
    return 0;
}
0