#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int>v[402], q[402];
int n, k, level[402], st[402], dr[402], pz;
void dfs(int dad, int nod)
{
if(nod)
level[nod] = level[dad] + 1;
if(level[nod] == k-1)
{
st[nod] = pz++;
dr[nod] = pz;
return;
}
st[nod] = pz;
for(int i = 0; i < v[nod].size(); ++i)
{
int vecin = v[nod][i];
if(vecin == dad)
continue;
dfs(nod, vecin);
}
dr[nod] = pz;
}
bool dp[402][(1<<20)];
bool solve()
{
dp[0][0] = 1;
for(int i = 1; i < n; ++i)
q[st[i]].push_back(i);
for(int i = 0; i < pz; ++i)
{
for(int j = 0; j < (1<<k); ++j)
{
if (!dp[i][j])
continue;
for(int jj = 0; jj < q[i].size(); ++jj)
{
int it = q[i][jj];
if (!(j >> level[it] & 1))
dp[dr[it]][j | (1<<level[it])] = 1;
}
}
}
for(int j = 0; j < (1<<k); ++j)
if (dp[pz][j])
return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
if(k * k >= n)
{
cout << "DA\n";
return 0;
}
for(int i = 1; i < n; ++i)
{
int a, b;
cin >> a >> b;
--a, --b;
v[a].pb(b);
v[b].pb(a);
}
level[0] = -1;
dfs(-1, 0);
cout << (solve() ? "DA" : "NE");
return 0;
}
Compilation message
burza.cpp: In function 'void dfs(int, int)':
burza.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0; i < v[nod].size(); ++i)
| ~~^~~~~~~~~~~~~~~
burza.cpp: In function 'bool solve()':
burza.cpp:40:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int jj = 0; jj < q[i].size(); ++jj)
| ~~~^~~~~~~~~~~~~
burza.cpp: In function 'int main()':
burza.cpp:69:14: error: 'class std::vector<int>' has no member named 'pb'
69 | v[a].pb(b);
| ^~
burza.cpp:70:14: error: 'class std::vector<int>' has no member named 'pb'
70 | v[b].pb(a);
| ^~