結果

問題 No.417 チューリップバブル
ユーザー nenuonnenuon
提出日時 2017-07-08 18:49:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 93,732 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-16 06:27:05
合計ジャッジ時間 2,422 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,264 KB
testcase_01 AC 8 ms
11,520 KB
testcase_02 AC 7 ms
11,392 KB
testcase_03 AC 7 ms
11,392 KB
testcase_04 AC 8 ms
11,264 KB
testcase_05 AC 7 ms
11,264 KB
testcase_06 AC 7 ms
11,392 KB
testcase_07 AC 7 ms
11,264 KB
testcase_08 AC 8 ms
11,392 KB
testcase_09 AC 8 ms
11,392 KB
testcase_10 AC 8 ms
11,648 KB
testcase_11 AC 12 ms
11,392 KB
testcase_12 AC 10 ms
11,648 KB
testcase_13 AC 11 ms
11,648 KB
testcase_14 AC 13 ms
11,392 KB
testcase_15 AC 8 ms
11,392 KB
testcase_16 AC 8 ms
11,648 KB
testcase_17 AC 13 ms
11,520 KB
testcase_18 AC 12 ms
11,520 KB
testcase_19 AC 11 ms
11,776 KB
testcase_20 AC 21 ms
11,520 KB
testcase_21 AC 22 ms
11,648 KB
testcase_22 AC 21 ms
11,520 KB
testcase_23 AC 21 ms
11,520 KB
testcase_24 AC 8 ms
11,520 KB
testcase_25 AC 21 ms
11,776 KB
testcase_26 AC 9 ms
11,392 KB
testcase_27 AC 17 ms
11,520 KB
testcase_28 AC 22 ms
11,520 KB
testcase_29 AC 25 ms
11,648 KB
testcase_30 AC 26 ms
11,520 KB
testcase_31 AC 20 ms
11,520 KB
testcase_32 AC 7 ms
11,264 KB
testcase_33 AC 7 ms
11,520 KB
testcase_34 AC 8 ms
11,392 KB
testcase_35 AC 34 ms
11,776 KB
testcase_36 AC 26 ms
11,776 KB
testcase_37 AC 46 ms
11,648 KB
testcase_38 AC 33 ms
11,648 KB
testcase_39 AC 22 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

const int MMAX = 2222;
const int NMAX = 222;
ll N, M;
ll dp[NMAX][MMAX][2]; // 頂点番号, 時間, 0は確定バージョン
ll U[NMAX];
bool visited[NMAX];
vector<vector<ll> > G(NMAX);
ll C[NMAX][NMAX]; // かかる時間

void dfs(int v){
  visited[v] = true;
  dp[v][0][0] = U[v];
  for(auto &to : G[v]){
    if(!visited[to]){
      dfs(to);
      // 一個後ろ
      FOR(i,0,M+1){
        if(dp[to][i][0] == 0) continue;
        // 今のところにたす
        FOR(j,0,M+1){
          if(dp[v][j][0] == 0) continue;
          if(j + i + 2 * C[v][to] > M) continue;
          dp[v][j + i + 2 * C[v][to]][1] = max(dp[v][j + i + 2 * C[v][to]][1], dp[v][j][0] + dp[to][i][0]);
        }
      }
      // 更新
      FOR(i,0,M+1){
        dp[v][i][0] = max(dp[v][i][0], dp[v][i][1]);
      }
    }
  }
  return;
}

int main(){
  cin >> N >> M;
  FOR(i,0,N) cin >> U[i];
  FOR(i,0,N-1){
    ll a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(b);
    G[b].push_back(a);
    C[a][b] = c;
    C[b][a] = c;
  }
  FOR(i,0,NMAX) FOR(j,0,MMAX) FOR(k,0,2) dp[i][j][k] = 0;
  dfs(0);
  ll ans = 0;
  FOR(i,0,M+1){
    ans = max(ans, dp[0][i][0]);
  }
  printf("%lld\n", ans);
  return 0;
}
0