結果

問題 No.417 チューリップバブル
ユーザー jimmyo0705jimmyo0705
提出日時 2018-09-25 21:08:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,173 ms / 2,000 ms
コード長 2,076 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 102,516 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 18:22:57
合計ジャッジ時間 18,890 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,812 KB
testcase_01 AC 39 ms
6,944 KB
testcase_02 AC 39 ms
6,944 KB
testcase_03 AC 39 ms
6,940 KB
testcase_04 AC 9 ms
6,944 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 44 ms
6,940 KB
testcase_07 AC 44 ms
6,944 KB
testcase_08 AC 85 ms
6,940 KB
testcase_09 AC 85 ms
6,944 KB
testcase_10 AC 173 ms
6,940 KB
testcase_11 AC 176 ms
6,940 KB
testcase_12 AC 179 ms
6,948 KB
testcase_13 AC 279 ms
6,944 KB
testcase_14 AC 284 ms
6,940 KB
testcase_15 AC 291 ms
6,940 KB
testcase_16 AC 287 ms
6,944 KB
testcase_17 AC 583 ms
6,940 KB
testcase_18 AC 577 ms
6,940 KB
testcase_19 AC 581 ms
6,940 KB
testcase_20 AC 577 ms
6,940 KB
testcase_21 AC 575 ms
6,940 KB
testcase_22 AC 572 ms
6,944 KB
testcase_23 AC 575 ms
6,944 KB
testcase_24 AC 579 ms
6,940 KB
testcase_25 AC 561 ms
6,940 KB
testcase_26 AC 401 ms
6,944 KB
testcase_27 AC 398 ms
6,944 KB
testcase_28 AC 572 ms
6,940 KB
testcase_29 AC 572 ms
6,944 KB
testcase_30 AC 566 ms
6,944 KB
testcase_31 AC 568 ms
6,944 KB
testcase_32 AC 8 ms
6,940 KB
testcase_33 AC 23 ms
6,940 KB
testcase_34 AC 204 ms
6,944 KB
testcase_35 AC 1,165 ms
6,944 KB
testcase_36 AC 1,156 ms
6,940 KB
testcase_37 AC 1,163 ms
6,944 KB
testcase_38 AC 1,157 ms
6,940 KB
testcase_39 AC 1,173 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n,m;
ll u[200];

ll dp[200][2000+1];

struct edge{
	ll to,cost;
	edge(ll _to,ll _cost):to(_to),cost(_cost){}
};


void update(int now,int to,int c){
	for(int i = 2000;i>=0;i--){
		rep(j,2001){
			if(i-c-j >= 0)dp[now][i] = max(dp[now][i-c-j]+dp[to][j],dp[now][i]);
		}
	}
}

vector<edge> G[200];
bool used[200];

void solve(int now){
	used[now] = true;
	rep(i,G[now].size()){
		ll to = G[now][i].to;
		if(used[to])continue;
		solve(to);
		update(now,to,G[now][i].cost);
	}
}

int main(){
	cin >> n >> m;
	rep(i,n)cin >> u[i];
	rep(i,n-1){
		ll a,b,c;
		cin >> a >> b >> c;
		G[a].push_back(edge(b,2*c));
		G[b].push_back(edge(a,2*c));
	}
	rep(i,200)rep(j,2000+1)dp[i][j] = -INF;
	rep(i,n)dp[i][0] = u[i];
	solve(0);
	ll ans = 0;
	rep(i,m+1)ans = max(ans,dp[0][i]);
	cout << ans << endl;
}
0