#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 && r[node]) 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 |
189 ms |
8144 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 |
182 ms |
7224 KB |
Output is correct |
2 |
Correct |
179 ms |
7064 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
188 ms |
7160 KB |
Output is correct |
6 |
Correct |
3 ms |
1960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
7396 KB |
Output is correct |
2 |
Correct |
179 ms |
7160 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
3448 KB |
Output is correct |
2 |
Correct |
183 ms |
8288 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 |
174 ms |
6232 KB |
Output is correct |
2 |
Correct |
177 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 |
180 ms |
7544 KB |
Output is correct |
2 |
Correct |
177 ms |
6780 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 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 |
7544 KB |
Output is correct |
2 |
Correct |
175 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 |
177 ms |
6776 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
2688 KB |
Output is correct |
2 |
Correct |
181 ms |
7892 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 |
1152 KB |
Output is correct |
6 |
Correct |
2 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1444 KB |
Output is correct |
2 |
Correct |
183 ms |
7800 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 |
81 ms |
3268 KB |
Output is correct |
2 |
Correct |
201 ms |
7928 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
94 ms |
3424 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |