結果

問題 No.417 チューリップバブル
ユーザー keita1_atcoderkeita1_atcoder
提出日時 2022-05-27 00:01:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,068 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 185,940 KB
実行使用メモリ 161,640 KB
最終ジャッジ日時 2023-10-20 19:35:38
合計ジャッジ時間 29,431 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 32 ms
5,128 KB
testcase_09 AC 82 ms
5,960 KB
testcase_10 AC 94 ms
11,588 KB
testcase_11 AC 513 ms
19,904 KB
testcase_12 AC 591 ms
19,904 KB
testcase_13 AC 76 ms
23,336 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 555 ms
82,472 KB
testcase_20 TLE -
testcase_21 AC 1,998 ms
161,408 KB
testcase_22 AC 1,791 ms
161,408 KB
testcase_23 RE -
testcase_24 AC 4 ms
5,384 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 1,479 ms
81,152 KB
testcase_28 AC 1,946 ms
161,408 KB
testcase_29 TLE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 20 ms
4,348 KB
testcase_34 AC 161 ms
43,136 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<long long> U;

struct Edge{
    int to,w;
    Edge(int a,int b){
        to = a;
        w = b;
    }
    Edge(){}
};

vector<vector<Edge>> G;

vector<vector<vector<long long>>> memo;
long long DFS(int v,int a,int t,int p = -1){
    if(G[v][a].to==p) return DFS(v,a-1,t,p);
    if(a==-1) return 0;
    if(memo[v][a][t]!=-1) return memo[v][a][t];
    long long res = DFS(v,a-1,t,p);
    for(int j = 0;j <= (t-2*G[v][a].w);j++){
        res = max(res,DFS(v,a-1,t-2*G[v][a].w-j,p)+DFS(G[v][a].to,(int)G[G[v][a].to].size()-1,j,v)+U[G[v][a].to]);
    }
    memo[v][a][t] = res;
    return res;
}

int main(){
    int N,M;
    cin >> N >> M;
    U.assign(N,0);
    memo.assign(N,vector<vector<long long>>(N,vector<long long>(M+1,-1)));
    for(int i = 0;i < N;i++) cin >> U[i];
    G.assign(N,vector<Edge>(0));
    for(int i = 0;i < N-1;i++){
        int A,B,C;
        cin >> A >> B >> C;
        G[A].push_back(Edge(B,C));
        G[B].push_back(Edge(A,C));
    }
    cout << DFS(0,(int)G[0].size()-1,M)+U[0] << endl;
}
0