#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;
else {
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);
}
memset(l, 0x3f, sizeof l);
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] - 1][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 |
Correct |
21 ms |
1912 KB |
Output is correct |
2 |
Correct |
202 ms |
8184 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
7160 KB |
Output is correct |
2 |
Correct |
181 ms |
7064 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
185 ms |
7160 KB |
Output is correct |
6 |
Correct |
2 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
7288 KB |
Output is correct |
2 |
Correct |
177 ms |
7160 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
3576 KB |
Output is correct |
2 |
Correct |
182 ms |
8312 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
6264 KB |
Output is correct |
2 |
Correct |
183 ms |
7032 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
7460 KB |
Output is correct |
2 |
Correct |
177 ms |
6904 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1920 KB |
Output is correct |
6 |
Correct |
1 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
7416 KB |
Output is correct |
2 |
Correct |
184 ms |
7032 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
178 ms |
6776 KB |
Output is correct |
6 |
Correct |
2 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2680 KB |
Output is correct |
2 |
Correct |
194 ms |
7872 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1152 KB |
Output is correct |
6 |
Correct |
2 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1536 KB |
Output is correct |
2 |
Correct |
187 ms |
7804 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
1280 KB |
Output is correct |
6 |
Correct |
2 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
3360 KB |
Output is correct |
2 |
Correct |
184 ms |
7932 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
85 ms |
3448 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |