結果

問題 No.417 チューリップバブル
ユーザー whesonwheson
提出日時 2018-05-17 14:00:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 715 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 173,576 KB
実行使用メモリ 5,716 KB
最終ジャッジ日時 2023-09-10 22:30:50
合計ジャッジ時間 11,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 111 ms
4,380 KB
testcase_12 AC 111 ms
4,376 KB
testcase_13 AC 46 ms
4,376 KB
testcase_14 AC 175 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 92 ms
4,384 KB
testcase_18 AC 92 ms
4,380 KB
testcase_19 AC 92 ms
4,380 KB
testcase_20 AC 355 ms
4,396 KB
testcase_21 AC 354 ms
4,380 KB
testcase_22 AC 353 ms
4,664 KB
testcase_23 AC 354 ms
4,520 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 355 ms
4,620 KB
testcase_26 AC 33 ms
4,376 KB
testcase_27 AC 247 ms
4,376 KB
testcase_28 AC 355 ms
4,380 KB
testcase_29 AC 354 ms
4,380 KB
testcase_30 AC 355 ms
4,444 KB
testcase_31 AC 357 ms
4,520 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 15 ms
4,380 KB
testcase_34 AC 165 ms
4,376 KB
testcase_35 AC 711 ms
5,596 KB
testcase_36 AC 714 ms
5,356 KB
testcase_37 AC 715 ms
5,716 KB
testcase_38 AC 714 ms
5,620 KB
testcase_39 AC 714 ms
5,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template <typename T>
struct Edge{
    int to; T cost;
    Edge(int to, T cost) : to(to), cost(cost) {}
};
template <typename T>
using Edges = vector<Edge<T>>;
template <typename T>
using AdjList = vector<Edges<T>>;

/*************** using variables **************/
AdjList<int> adj;
int dp[205][2005];
int n, m;
vector<int> u;
/**********************************************/

void dfs(int cur, int pre){
    dp[cur][0] = u[cur];
    for(auto child: adj[cur]) if(child.to != pre){
        dfs(child.to, cur);
        
        for(int i = m; i >= 0; i--){
            REP(j, m+1){
                int t = i + child.cost * 2 + j;
                if(t <= m) dp[cur][t] = max(dp[cur][t], dp[cur][i] + dp[child.to][j]);
            }
        }
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> m;
    u.resize(n);
    REP(i, n) cin >> u[i];

    adj.resize(n);
    REP(i, n-1){
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].pb(Edge<int>(b, c));
        adj[b].pb(Edge<int>(a, c));
    }
    
    dfs(0, -1);
    int ans = 0;
    REP(i, m+1) ans = max(ans, dp[0][i]);
    cout << ans << endl;
}
0