結果

問題 No.417 チューリップバブル
ユーザー しらっ亭しらっ亭
提出日時 2016-08-26 23:53:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,163 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 175,016 KB
実行使用メモリ 813,812 KB
最終ジャッジ日時 2024-04-26 04:04:33
合計ジャッジ時間 5,126 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 128 ms
71,288 KB
testcase_12 AC 68 ms
36,708 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef long long ll;
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;

void Main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vi U(N);
  rep(i, N) scanf("%d", &U[i]);

  vector<vpii> E(N);
  rep(i, N-1) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    E[u].emplace_back(v, w);
    E[v].emplace_back(u, w);
  }

  function<vpii(int, int)> dfs = [&](int cur, int pre) {
    //_p("dfs(%d,%d)\n", cur,pre);
    vector<vpii> subs;
    forr(nex, E[cur]) {
      int nev = nex.fst;
      int nec = nex.snd;
      if (nev == pre) continue;
      vpii sub = dfs(nev, cur);
      forr(s, sub) {
        //_p("(%d,%d)\n", s.fst, s.snd);
        s.snd += nec * 2;
      }
      subs.push_back(sub);
    }
    /*
    _p("subz:%d\n", SZ(subs));
    rep(i, SZ(subs)) {
      auto &sub = subs[i];
      forr(s, sub) _p("%d:%d:(%d,%d)\n",cur,i,s.fst,s.snd);
    }
    */
    vpii ret;

    function<void(int, int , int)> rec = [&](int i, int b, int c) {
      if (c > M) return;
      if (i == SZ(subs)) {
        ret.emplace_back(U[cur] + b, c);
        return;
      }

      rec(i+1, b, c);
      forr(s, subs[i]) {
        int bb = b + s.fst;
        int cc = c + s.snd;
        rec(i+1, bb, cc);
      }
    };
    rec(0, 0, 0);
    //forr(s, ret) _p("%d: (%d,%d)\n",cur,s.fst,s.snd);
    return ret;
  };

  vpii ret = dfs(0, -1);
  int ans = 0;
  forr(s, ret) {
    if (s.snd <= M) ans = max(ans, s.fst);
  }
  _p("%d\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
0