This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
vector<int> eu;int en[401],lol[401];
vector<int> adj[401];
void dfs(int i,int pr,int dep){
eu.push_back(i);
lol[i] = dep;
for(auto j:adj[i]){
if(j==pr)continue;
dfs(j,i,dep+1);
}
en[i] = eu.size();
}
bool dp[401][(1<<20)];int n,k;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>k;
if(n<=k*k){
cout<<"DA\n";
return 0;
}
for(int i = 0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,0,-1);
for(int i = n;i>=1;i--){
for(int mask = 0;mask<(1<<k);mask++){
if(i==n){
dp[i&1][mask] = 0;
continue;
}
if(!(mask&(1<<lol[eu[i]]))){
dp[i&1][mask]|=dp[en[eu[i]]][mask|(1<<lol[eu[i]])];
}
if(lol[eu[i]]+1<k){
dp[i&1][mask]|=dp[i+1][mask];
}
}
}
cout<<(dp[1][0]?"DA":"NE")<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |