#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<long long,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 1000000007
#define MX 405
using namespace std;
int n,k;
int cnt=0, tim=0;
vi edges[MX], ed1[MX], dep(MX), ind(MX), revind(MX), paro(MX);
void dfs(int node, int par){
for(auto i:ed1[node]){
if(i==par) continue;
dep[i]=dep[node]+1;
dfs(i, node);
}
if(edges[node].size() || dep[node]==k){
cnt++;
if(par!=0){
edges[node].pb(par);
edges[par].pb(node);
}
}
}
void dfs2(int node, int par){
paro[node]=par;
ind[node]=++tim;
revind[ind[node]]=node;
for(auto i:edges[node]) if(i!=par) dfs2(i, node);
}
void solve(){
cin >> n >> k;
for(int i=1; i<n; i++){
int a,b; cin >> a >> b;
ed1[a].pb(b);
ed1[b].pb(a);
}
dep[1]=0;
dfs(1,0);
n=cnt;
if(k*k>=n){
cout << "DA\n";
return;
}
dfs2(1, 0);
bool dp[n+1][1<<k];
memset(dp,0,sizeof(dp));
int lolol[n+1];
lolol[1]=1;
for(int i=2; i<=n; i++){
if(i-1==ind[paro[revind[i]]]) lolol[i]=lolol[i-1];
else lolol[i]=i;
}
for(int i=2; i<=n; i++){
for(int j=0; j<1<<k; j++){
dp[i][j]|=dp[ind[paro[revind[i]]]][j];
if(j&(1<<(dep[revind[i]]-1))) dp[i][j]|=lolol[i]==1?1:dp[lolol[i]-1][j^(1<<(dep[revind[i]]-1))];
}
}
if(dp[n][(1<<k)-1]) cout << "DA\n";
else cout << "NE\n";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
/*freopen(".in","r",stdin);
freopen(".out","w",stdout);*/
int t=1;
//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4944 KB |
Output is correct |
2 |
Correct |
82 ms |
48208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
46152 KB |
Output is correct |
2 |
Correct |
87 ms |
46228 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
80 ms |
46420 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
46380 KB |
Output is correct |
2 |
Correct |
88 ms |
46416 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
496 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
11600 KB |
Output is correct |
2 |
Correct |
92 ms |
48456 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
44360 KB |
Output is correct |
2 |
Correct |
87 ms |
45968 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
46788 KB |
Output is correct |
2 |
Correct |
83 ms |
45288 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
47176 KB |
Output is correct |
2 |
Correct |
96 ms |
45752 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
88 ms |
45640 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
10320 KB |
Output is correct |
2 |
Correct |
88 ms |
47688 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4432 KB |
Output is correct |
2 |
Correct |
93 ms |
47584 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
20056 KB |
Output is correct |
2 |
Correct |
95 ms |
47748 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
41 ms |
20304 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |