#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=0; 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(rng[j][i]==0){
dp[mask][i]=true;
break;
}
if(dp[mask^J][rng[j][i]-1]){
dp[mask][i]=true;
break;
}
}
}
if(dp[mask][last-1]){
ans="DA";
break;
}
}
cout<<ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
1624 KB |
Output is correct |
2 |
Correct |
360 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 |
328 ms |
9564 KB |
Output is correct |
2 |
Correct |
323 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 |
331 ms |
9564 KB |
Output is correct |
2 |
Correct |
322 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 |
104 ms |
2652 KB |
Output is correct |
2 |
Correct |
354 ms |
9560 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
291 ms |
9560 KB |
Output is correct |
2 |
Correct |
324 ms |
9716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
327 ms |
9560 KB |
Output is correct |
2 |
Correct |
344 ms |
9564 KB |
Output is correct |
3 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
9564 KB |
Output is correct |
2 |
Correct |
317 ms |
9560 KB |
Output is correct |
3 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
2648 KB |
Output is correct |
2 |
Correct |
347 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 |
34 ms |
1628 KB |
Output is correct |
2 |
Correct |
347 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 |
134 ms |
5080 KB |
Output is correct |
2 |
Correct |
371 ms |
9560 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |