#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=400+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
bitset<(1<<20)+1> dp[N*2][2];
bool pod[N];
vi graf[N];
int n,k,wsk,pierw[N],level[N];
void dfs(int v,int o){
if(level[v]==k-1) pod[v]=1;
for(auto u:graf[v]){
if(u==o) continue;
level[u]=level[v]+1;
dfs(u,v);
pod[v]|=pod[u];
}
}
void dfs2(int v,int o){
wsk++;
pierw[v]=wsk;
if(v!=1){
for(int i=0;i<(1<<k);i++){
if(i&(1<<level[v])) dp[wsk][1][i]=max(dp[wsk-1][1][i],dp[wsk-1][0][i-(1<<level[v])]);
else dp[wsk][1][i]=dp[wsk-1][1][i];
}
if(level[v]!=k-1) dp[wsk][0]=dp[wsk-1][0];
else dp[wsk][0]=dp[wsk][1];
}
for(auto u:graf[v]){
if(u==o or !pod[u] or level[u]==k) continue;
dfs2(u,v);
}
if(v==1) return;
wsk++;
dp[wsk][0]=dp[wsk-1][0],dp[wsk][1]=dp[pierw[o]][1];
}
void solve(){
cin>>n>>k;
for(int a,b,i=1;i<n;i++){
cin>>a>>b;
graf[a].push_back(b),graf[b].push_back(a);
}
if(k*k>=n){
cout<<"DA\n";
return;
}
level[1]=-1;
dfs(1,1);
for(int i=0;i<(1<<k);i++) dp[1][0][i]=1;
dfs2(1,1);
cout<<(dp[wsk][0][(1<<k)-1]?"DA":"NE")<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
113868 KB |
Output is correct |
2 |
Correct |
238 ms |
150584 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
60 ms |
139172 KB |
Output is correct |
6 |
Correct |
12 ms |
24788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
144132 KB |
Output is correct |
2 |
Correct |
226 ms |
144040 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
224 ms |
144908 KB |
Output is correct |
6 |
Correct |
61 ms |
144972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
145000 KB |
Output is correct |
2 |
Correct |
231 ms |
144508 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
47 ms |
111580 KB |
Output is correct |
6 |
Correct |
13 ms |
30292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
136652 KB |
Output is correct |
2 |
Correct |
236 ms |
151436 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
38 ms |
94764 KB |
Output is correct |
6 |
Correct |
10 ms |
21716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
138448 KB |
Output is correct |
2 |
Correct |
231 ms |
143692 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
62 ms |
141568 KB |
Output is correct |
6 |
Correct |
44 ms |
99484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
247 ms |
145804 KB |
Output is correct |
2 |
Correct |
229 ms |
141712 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
56 ms |
129096 KB |
Output is correct |
6 |
Correct |
39 ms |
83532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
147388 KB |
Output is correct |
2 |
Correct |
241 ms |
142928 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
232 ms |
142452 KB |
Output is correct |
6 |
Correct |
52 ms |
112716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
121360 KB |
Output is correct |
2 |
Correct |
233 ms |
148608 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
42 ms |
83484 KB |
Output is correct |
6 |
Correct |
66 ms |
145444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
99948 KB |
Output is correct |
2 |
Correct |
233 ms |
148556 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
41 ms |
85448 KB |
Output is correct |
6 |
Correct |
59 ms |
130272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
121144 KB |
Output is correct |
2 |
Correct |
235 ms |
148988 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
134 ms |
123112 KB |
Output is correct |
6 |
Correct |
28 ms |
58968 KB |
Output is correct |