#include <bits/stdc++.h>
#define ll long long
#define ld double
using namespace std;
int n, k, K, last;
vector<vector<int> > adj, rng;
vector<vector<bool> > dp;
vector<int> l, r, d;
int inf=1e9;
void dfs(int a, int b){
if(a==b)d[a]=0;
else d[a]=d[b]+1;
if(d[a]==k){
l[a]=++last;
r[a]=last;
return;
}
for(auto x:adj[a]){
if(x==b)continue;
dfs(x, a);
l[a]=min(l[a], l[x]);
r[a]=max(r[a], r[x]);
}
}
int main()
{ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int Tc=1;//cin>>Tc;
while(Tc--)
{
cin>>n>>k;
adj.assign(n+1, vector<int>());
for(int i=1;i<n;++i){
int u, v;cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if(k>20){cout<<"DA";continue;}
d.assign(n+1, 0);
l.assign(n+1, inf);
r.assign(n+1, -inf);
dfs(1, 1);
rng.assign(k+1, vector<int>(last+1, -1) );
for(int i=2;i<=n;++i){
if(l[i]==inf)continue;
rng[d[i]][r[i]]=l[i];
}
K=(1<<k);
dp.assign(K, vector<bool>(last+1, false));
string ans="NE";
dp[0][0]=true;
for(int mask=1; mask<K; ++mask){
dp[mask][0]=true;
for(int i=1; i<=last; ++i){
for(int j=1, J=1; j<=k; ++j, J<<=1){
if((mask&J)==0)continue;
if(rng[j][i]==-1)continue;
if(dp[mask^J][rng[j][i]-1]){
dp[mask][i]=true;
break;
}
}
}
if(dp[mask][last]){
ans="DA";
break;
}
}
cout<<ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
1628 KB |
Output is correct |
2 |
Correct |
390 ms |
9560 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
9560 KB |
Output is correct |
2 |
Correct |
350 ms |
9564 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
344 ms |
9564 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
351 ms |
9564 KB |
Output is correct |
2 |
Correct |
349 ms |
9564 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
2648 KB |
Output is correct |
2 |
Correct |
386 ms |
9560 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
9564 KB |
Output is correct |
2 |
Correct |
364 ms |
9508 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
355 ms |
9564 KB |
Output is correct |
2 |
Correct |
322 ms |
9564 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
370 ms |
9564 KB |
Output is correct |
2 |
Correct |
335 ms |
9564 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
332 ms |
9696 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
2652 KB |
Output is correct |
2 |
Correct |
375 ms |
9560 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
404 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1624 KB |
Output is correct |
2 |
Correct |
378 ms |
9560 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
4956 KB |
Output is correct |
2 |
Correct |
401 ms |
9560 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
144 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |