結果

問題 No.417 チューリップバブル
ユーザー ferinferin
提出日時 2017-08-17 15:49:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 772 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 161,528 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-22 14:32:10
合計ジャッジ時間 11,807 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 120 ms
5,376 KB
testcase_12 AC 119 ms
5,376 KB
testcase_13 AC 49 ms
5,376 KB
testcase_14 AC 189 ms
5,376 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 98 ms
5,376 KB
testcase_18 AC 99 ms
5,376 KB
testcase_19 AC 100 ms
5,376 KB
testcase_20 AC 381 ms
5,376 KB
testcase_21 AC 383 ms
5,376 KB
testcase_22 AC 381 ms
5,376 KB
testcase_23 AC 381 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 383 ms
5,376 KB
testcase_26 AC 36 ms
5,376 KB
testcase_27 AC 266 ms
5,376 KB
testcase_28 AC 381 ms
5,376 KB
testcase_29 AC 379 ms
5,376 KB
testcase_30 AC 380 ms
5,376 KB
testcase_31 AC 382 ms
5,376 KB
testcase_32 AC 5 ms
5,376 KB
testcase_33 AC 16 ms
5,376 KB
testcase_34 AC 167 ms
5,376 KB
testcase_35 AC 772 ms
5,504 KB
testcase_36 AC 767 ms
5,504 KB
testcase_37 AC 772 ms
5,632 KB
testcase_38 AC 770 ms
5,504 KB
testcase_39 AC 768 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

struct edge{int to, cost;};
vector<edge> g[205];
int u[205];
int n, m;
ll dp[205][2010];
void dfs(int v, int p) {
  dp[v][0] = u[v];
  for(auto i: g[v]) {
    if(i.to == p) continue;
    dfs(i.to, v);
    for(int j=m; j>=0; --j) REP(k, m+1) {
      int t = j+i.cost*2+k;
      if(t <= m) chmax(dp[v][t], dp[v][j] + dp[i.to][k]);
    }
  }
}


signed main(void)
{
  cin >> n >> m;
  REP(i, n) cin >> u[i];
  REP(i, n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].PB({b, c});
    g[b].PB({a, c});
  }

  dfs(0, -1);

  ll ans = 0;
  REP(i, m+1) chmax(ans, dp[0][i]);
  cout << ans << endl;

  return 0;
}
0