結果

問題 No.196 典型DP (1)
ユーザー pionepione
提出日時 2020-07-24 03:54:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,651 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 171,412 KB
実行使用メモリ 814,564 KB
最終ジャッジ日時 2023-09-06 10:56:20
合計ジャッジ時間 4,697 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



vll G[2005];
ll n,k;

ll cnts[2005];
void prep(ll v, ll p){
  cnts[v]=1;
  for(auto nv: G[v]){
    if(nv==p) continue;
    prep(nv,v);
    cnts[v]+=cnts[nv];
  }
}

ll sz;
vll dp;
ll ans=0;
void dfs2(vvll &child, ll sum, ll i){
  if(i==sz){
    if(sum==k) ans++;
    else if(sum!=0) dp.push_back(sum);
    return;
  }
  
  ll isz=child[i].size();
  rep(j,isz+1){
    if(j==isz) dfs2(child,sum,i+1);
    else dfs2(child,sum+child[i][j],i+1);
  }
}

vll dfs(ll v, ll p){
	vvll child;
	for(auto &nv: G[v]){
		if(nv==p) continue;
		auto c=dfs(nv,v);
		child.push_back(c);
	}
	
	sz=child.size();
  dp.clear();
	if(sz>0) dfs2(child,0,0);
  dp.push_back(cnts[v]);
  
  // cout<<"v="<<v<<' '<<ans<<endl;
  // if(v==0){
  //   rep(i,sz) {
  //     for(auto c: child[i]){
  //       cout<<c<<' ';
  //     }
  //     cout<<endl;
  //   }
  // }
	
	return dp;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>k;
  rep(i,n-1){
    ll a,b; cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  prep(0,-1);
  dfs(0,-1);
  if(cnts[0]==k) ans++;
  cout<<ans<<endl;
  
}
0