結果

問題 No.417 チューリップバブル
ユーザー latte0119latte0119
提出日時 2016-08-26 22:55:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 162,028 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 21:40:57
合計ジャッジ時間 7,316 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 15 ms
6,940 KB
testcase_11 AC 63 ms
6,940 KB
testcase_12 AC 62 ms
6,940 KB
testcase_13 AC 25 ms
6,940 KB
testcase_14 AC 100 ms
6,944 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 55 ms
6,940 KB
testcase_18 AC 57 ms
6,944 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 227 ms
6,940 KB
testcase_21 AC 212 ms
6,940 KB
testcase_22 AC 210 ms
6,940 KB
testcase_23 AC 218 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 216 ms
6,944 KB
testcase_26 AC 22 ms
6,944 KB
testcase_27 AC 149 ms
6,944 KB
testcase_28 AC 213 ms
6,940 KB
testcase_29 AC 217 ms
6,944 KB
testcase_30 AC 225 ms
6,944 KB
testcase_31 AC 223 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 7 ms
6,940 KB
testcase_34 AC 45 ms
6,944 KB
testcase_35 AC 456 ms
6,944 KB
testcase_36 AC 449 ms
6,940 KB
testcase_37 AC 457 ms
6,940 KB
testcase_38 AC 451 ms
6,940 KB
testcase_39 AC 432 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     scanf("%lld%lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:41:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     rep(i,N)scanf("%lld",&U[i]);
      |             ~~~~~^~~~~~~~~~~~~~
main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         scanf("%lld%lld%lld",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int N,M;
int U[200];
vector<edge>G[200];
int dp[200][2001];
void dfs(int v,int p){
    rep(i,M+1)dp[v][i]=U[v];
    for(auto e:G[v]){
        if(e.to==p)continue;
        dfs(e.to,v);
        for(int i=M;i-e.cost*2>=0;i--){
            for(int j=0;j+e.cost*2<=i;j++){
                chmax(dp[v][i],dp[v][i-j-e.cost*2]+dp[e.to][j]);
            }
        }
    }
}
signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,N)scanf("%lld",&U[i]);
    rep(i,N-1){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        G[a].pb(edge(b,c));
        G[b].pb(edge(a,c));
    }

    dfs(0,-1);
    printf("%lld\n",dp[0][M]);
    return 0;
}
0