結果

問題 No.417 チューリップバブル
ユーザー ei1333333ei1333333
提出日時 2016-08-26 22:39:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 764 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 149,296 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 03:47:54
合計ジャッジ時間 11,493 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 30 ms
4,376 KB
testcase_11 AC 119 ms
4,376 KB
testcase_12 AC 120 ms
4,384 KB
testcase_13 AC 48 ms
4,376 KB
testcase_14 AC 188 ms
4,376 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 97 ms
4,376 KB
testcase_18 AC 97 ms
4,376 KB
testcase_19 AC 97 ms
4,376 KB
testcase_20 AC 381 ms
4,376 KB
testcase_21 AC 378 ms
4,380 KB
testcase_22 AC 377 ms
4,376 KB
testcase_23 AC 378 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 378 ms
4,376 KB
testcase_26 AC 34 ms
4,376 KB
testcase_27 AC 267 ms
4,376 KB
testcase_28 AC 378 ms
4,376 KB
testcase_29 AC 377 ms
4,380 KB
testcase_30 AC 378 ms
4,380 KB
testcase_31 AC 384 ms
4,380 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 16 ms
4,376 KB
testcase_34 AC 166 ms
4,376 KB
testcase_35 AC 760 ms
4,376 KB
testcase_36 AC 760 ms
4,380 KB
testcase_37 AC 764 ms
4,380 KB
testcase_38 AC 764 ms
4,376 KB
testcase_39 AC 763 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long

struct edge
{
  int to, cost;
};
int N, M, U[200];
vector< edge > g[200];

vector< int > rec(int idx, int par = -1)
{
  vector< int > dp(M + 1, 0);
  dp[0] = U[idx];
  for(auto e : g[idx]) {
    if(par == e.to) continue;
    vector< int > pp = rec(e.to, idx);
    for(int j = M; j >= 0; j--) {
      for(int k = M; k >= 0; k--) {
        int next = k + j + e.cost * 2;
        if(next > M) continue;
        dp[next] = max(dp[next], dp[j] + pp[k]);
      }
    }
  }
  return (dp);
}

signed main()
{
  cin >> N >> M;
  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;
    g[A].push_back((edge) {B, C});
    g[B].push_back((edge) {A, C});
  }
  auto p = rec(0);
  cout << *max_element(begin(p), end(p)) << endl;
}
0