結果
| 問題 |
No.417 チューリップバブル
|
| ユーザー |
hashiryo
|
| 提出日時 | 2018-12-20 16:59:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 321 ms / 2,000 ms |
| コード長 | 1,646 bytes |
| コンパイル時間 | 1,076 ms |
| コンパイル使用メモリ | 104,104 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 09:05:17 |
| 合計ジャッジ時間 | 5,801 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;
struct Edge{
int src,dst;
ll weight;
Edge(int a,int b,ll c):src(a),dst(b),weight(c){}
};
int N,M;
ll U[210];
vector<vector<Edge> > G;
ll dp[210][2100];
void dfs(int v,int par){
repeat(i,M+1){
dp[v][i]=U[v];
}
for(Edge e:G[v])if(e.dst!=par){
dfs(e.dst,v);
for(int m=M;m>=0;m--){
repeat(i,m-2*e.weight+1){
dp[v][m]=max(dp[v][m],dp[v][m-i-2*e.weight]+dp[e.dst][i]);
}
}
}
//debug(v);
//debugArray(dp[v],M+1);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
G.resize(N);
repeat(i,N){
cin >> U[i];
}
//debugArray(U,N);
repeat(i,N-1){
int a,b;ll c;
cin >> a >> b >> c;
G[a].push_back({a,b,c});
G[b].push_back({b,a,c});
}
dfs(0,-1);
cout << dp[0][M] << endl;
return 0;
}
hashiryo