結果

問題 No.417 チューリップバブル
ユーザー cormorancormoran
提出日時 2016-12-20 18:21:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,290 bytes
コンパイル時間 4,244 ms
コンパイル使用メモリ 184,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 03:20:38
合計ジャッジ時間 4,677 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 16 ms
4,380 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 17 ms
4,376 KB
testcase_20 AC 33 ms
4,380 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 38 ms
4,376 KB
testcase_23 AC 32 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 38 ms
4,380 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 16 ms
4,376 KB
testcase_28 AC 53 ms
4,380 KB
testcase_29 AC 69 ms
4,380 KB
testcase_30 AC 30 ms
4,380 KB
testcase_31 AC 47 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 76 ms
4,380 KB
testcase_36 AC 71 ms
4,380 KB
testcase_37 AC 53 ms
4,380 KB
testcase_38 AC 47 ms
4,380 KB
testcase_39 AC 21 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    int N, M;
    vector<int> U;
    vector<vector<pii>> E;

    vector<map<int, int>> memo;

    void rec(int now, int pre) {
        // cerr << "@" << now << " from " << pre << endl;
        memo[now][0] = U[now];
        
        for(auto e: E[now]) {
            if(e.first == pre) continue;
            rec(e.first, now);

            map<int, int> mp;
            for(auto np : memo[now]) {
                for(auto p : memo[e.first]) {                
                    int m = p.first + np.first + e.second * 2;
                    if(m <= M) set_max(mp[m], p.second + np.second);
                }
            }
            for(auto p : mp) {
                set_max(memo[now][p.first], p.second);
            }
        }
    }
    
    bool solve() {
        cin >> N >> M;
        U.resize(N); cin >> U;
        E.resize(N);
        rep(i, N - 1) {
            int a, b, c; cin >> a >> b >> c;
            E[a].push_back(make_pair(b, c));
            E[b].push_back(make_pair(a, c));
        }

        memo.resize(N);

        rec(0, -1);
        int ans = 0;
        for(auto p : memo[0]) {            
            set_max(ans, p.second);
        }

        cout << ans << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0