This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 405
#define maxm 21
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,k,st[maxn],en[maxn],leaf,h[maxn];
bool dp[maxn][1 << maxm];
vector <int> a[maxn],b[maxn];
void Dfs(int u,int par)
{
if (h[u] == k - 1)
{
st[u] = leaf++;
en[u] = leaf;
return;
}
st[u] = leaf;
for (int v : a[u])
if (v != par)
{
h[v] = h[u] + 1;
Dfs(v,u);
}
en[u] = leaf;
}
int main()
{
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
//freopen(Task".inp", "r",stdin);
//freopens(Task".out", "w",stdout);
cin >> n >> k;
if (k * k >= n) return cout << "DA",0;
FOR(i,1,n-1)
{
int x,y;
cin >> x >> y;
a[x].pb(y);
a[y].pb(x);
}
h[1] = -1;
Dfs(1,0);
FOR(i,2,n) b[st[i]].pb(i);
dp[0][0] = 1;
FOR(i,0,leaf - 1)
FOR(j,0,(1 << k) - 1)
{
if (!dp[i][j]) continue;
for (int v : b[i])
if ((j >> h[v]) & 1);
else
{
dp[en[v]][j + (1 << h[v])] = 1;
}
}
FOR(i,0,(1 << k) - 1)
if (dp[leaf][i])
{
return cout << "DA",0;
}
cout << "NE";
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... |