#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<<"NE";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 |
44 ms |
1628 KB |
Output is correct |
2 |
Correct |
387 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
9560 KB |
Output is correct |
2 |
Correct |
345 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
355 ms |
9564 KB |
Output is correct |
2 |
Correct |
375 ms |
9560 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
2652 KB |
Output is correct |
2 |
Correct |
383 ms |
9816 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
305 ms |
9564 KB |
Output is correct |
2 |
Correct |
356 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
9564 KB |
Output is correct |
2 |
Correct |
328 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
365 ms |
9564 KB |
Output is correct |
2 |
Correct |
339 ms |
9672 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
2648 KB |
Output is correct |
2 |
Correct |
378 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1628 KB |
Output is correct |
2 |
Correct |
375 ms |
9560 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
4956 KB |
Output is correct |
2 |
Correct |
374 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |