結果

問題 No.417 チューリップバブル
ユーザー parukiparuki
提出日時 2016-08-27 09:18:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 1,263 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 170,756 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 06:07:14
合計ジャッジ時間 6,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 12 ms
5,376 KB
testcase_11 AC 59 ms
5,376 KB
testcase_12 AC 54 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 66 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 42 ms
5,376 KB
testcase_18 AC 47 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 162 ms
5,376 KB
testcase_21 AC 179 ms
5,376 KB
testcase_22 AC 164 ms
5,376 KB
testcase_23 AC 165 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 146 ms
5,376 KB
testcase_26 AC 16 ms
5,376 KB
testcase_27 AC 117 ms
5,376 KB
testcase_28 AC 177 ms
5,376 KB
testcase_29 AC 167 ms
5,376 KB
testcase_30 AC 177 ms
5,376 KB
testcase_31 AC 170 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 14 ms
5,376 KB
testcase_35 AC 317 ms
5,376 KB
testcase_36 AC 340 ms
5,376 KB
testcase_37 AC 252 ms
5,376 KB
testcase_38 AC 290 ms
5,376 KB
testcase_39 AC 285 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct E{
    int to, w;
};

int dp[200][2001], M;
vector<vector<E>> G;
vi U;

void f(int u, int p){
    dp[u][0] = U[u];
    each(e, G[u]){
        if(e.to == p)continue;
        f(e.to, u);
        for(int m = M-e.w; m >= 0; --m)if(dp[u][m]!=-1){
            rep(mm, M - m - e.w + 1){
                smax(dp[u][m + e.w + mm], dp[u][m] + dp[e.to][mm]);
            }
        }
    }
    rep(i, M)smax(dp[u][i + 1], dp[u][i]);
}

int main(){
    int N, a, b, c;

    cin >> N >> M;
    G.resize(N);
    U.resize(N);
    rep(i, N) scanf("%d", &U[i]);
    rep(i, N-1){
        scanf("%d%d%d", &a, &b, &c);
        c *= 2;
        G[a].push_back(E{b,c});
        G[b].push_back(E{a,c});
    }
    MEM(dp, -1);
    f(0, -1);
    cout << dp[0][M] << endl;
}
0