結果

問題 No.417 チューリップバブル
ユーザー mayoko_mayoko_
提出日時 2016-08-27 00:11:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 866 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 104,272 KB
実行使用メモリ 16,560 KB
最終ジャッジ日時 2023-08-08 11:12:51
合計ジャッジ時間 11,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,240 KB
testcase_01 AC 5 ms
9,176 KB
testcase_02 AC 5 ms
9,292 KB
testcase_03 AC 5 ms
9,180 KB
testcase_04 AC 5 ms
9,160 KB
testcase_05 AC 5 ms
9,112 KB
testcase_06 AC 5 ms
9,432 KB
testcase_07 AC 6 ms
9,160 KB
testcase_08 AC 11 ms
9,436 KB
testcase_09 AC 21 ms
9,444 KB
testcase_10 AC 23 ms
9,680 KB
testcase_11 AC 99 ms
10,332 KB
testcase_12 AC 113 ms
10,428 KB
testcase_13 AC 18 ms
10,232 KB
testcase_14 AC 151 ms
10,948 KB
testcase_15 AC 17 ms
9,548 KB
testcase_16 AC 15 ms
9,748 KB
testcase_17 AC 95 ms
10,932 KB
testcase_18 AC 99 ms
10,916 KB
testcase_19 AC 101 ms
10,912 KB
testcase_20 AC 384 ms
12,768 KB
testcase_21 AC 360 ms
12,796 KB
testcase_22 AC 321 ms
12,792 KB
testcase_23 AC 379 ms
12,908 KB
testcase_24 AC 6 ms
9,200 KB
testcase_25 AC 358 ms
12,732 KB
testcase_26 AC 35 ms
10,000 KB
testcase_27 AC 269 ms
11,640 KB
testcase_28 AC 351 ms
12,924 KB
testcase_29 AC 367 ms
12,924 KB
testcase_30 AC 360 ms
12,948 KB
testcase_31 AC 370 ms
12,800 KB
testcase_32 AC 6 ms
9,176 KB
testcase_33 AC 10 ms
9,320 KB
testcase_34 AC 33 ms
11,004 KB
testcase_35 AC 775 ms
16,560 KB
testcase_36 AC 800 ms
16,476 KB
testcase_37 AC 729 ms
16,256 KB
testcase_38 AC 788 ms
16,328 KB
testcase_39 AC 866 ms
16,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 222;
const int MAXM = 1101;
ll U[MAXN];

struct Edge {
    int to;
    int cost;
    Edge() {}
    Edge(int t, int c) : to(t), cost(c) {}
};

vector<Edge> es[MAXN];

vector<ll> dp[MAXN][MAXM];

ll dfs(int v, int rest, int now, int p) {
    ll& ret = dp[v][rest][now];
    if (ret >= 0) return ret;
    if (now == es[v].size()) return ret = U[v];
    ret = dfs(v, rest, now+1, p);
    Edge e = es[v][now];
    if (e.to != p && e.cost <= rest) {
        for (int i = 0; i <= rest-e.cost; i++) {
            ret = max(ret, dfs(e.to, i, 0, v) + dfs(v, rest-e.cost-i, now+1, p));
        }
    }

    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    M /= 2;
    for (int i = 0; i < N; i++)
        cin >> U[i];
    for (int i = 0; i < N-1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        es[a].emplace_back(b, c);
        es[b].emplace_back(a, c);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= M; j++) {
            dp[i][j].resize(es[i].size()+1, -1);
        }
    }
    cout << dfs(0, M, 0, -1) << endl;
    return 0;
}
0