#include <bits/stdc++.h>
using namespace std;
int n, k, depth[401], l[401], r[401], cnt = 0;
vector<int> graph[401], to_check[401];
bool dp[401][1 << 20];
void dfs(int node = 1, int parent = 0) {
if (depth[node] == k) {
l[node] = r[node] = ++cnt;
return;
}
for (int i : graph[node]) if (i != parent) {
depth[i] = depth[node] + 1;
dfs(i, node);
l[node] = min(l[node], l[i]);
r[node] = max(r[node], r[i]);
}
if (node != 1) to_check[r[node]].push_back(node);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
if (k * k > n) return cout << "DA", 0;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs();
for (int i = 1; i <= n; i++) depth[i]--;
dp[0][0] = true;
for (int i = 1; i <= cnt; i++) {
for (int j = 0; j < (1 << k); j++) {
for (int k : to_check[i]) {
if (j & (1 << depth[k])) {
dp[i][j] |= dp[l[k]][j ^ (1 << depth[k])];
}
}
}
}
for (int i = 0; i < (1 << k); i++) {
if (dp[cnt][i]) return cout << "DA", 0;
}
cout << "NE";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
151 ms |
2808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
3064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
1400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
170 ms |
2808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
152 ms |
2808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
3492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
1144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
1676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |