#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();
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] - 1)) {
dp[i][j] |= dp[l[k] - 1][j ^ (1 << depth[k] - 1)];
}
}
}
}
for (int i = 0; i < (1 << k); i++) {
if (dp[cnt][i]) return cout << "DA", 0;
}
cout << "NE";
return 0;
}
Compilation message
burza.cpp: In function 'int main()':
burza.cpp:39:28: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if (j & (1 << depth[k] - 1)) {
~~~~~~~~~^~~
burza.cpp:40:50: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
dp[i][j] |= dp[l[k] - 1][j ^ (1 << depth[k] - 1)];
~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1920 KB |
Output is correct |
2 |
Correct |
179 ms |
8312 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 |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
7256 KB |
Output is correct |
2 |
Correct |
183 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 |
182 ms |
7288 KB |
Output is correct |
6 |
Correct |
2 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
7160 KB |
Output is correct |
2 |
Correct |
175 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 |
42 ms |
3448 KB |
Output is correct |
2 |
Correct |
183 ms |
8296 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 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 |
171 ms |
6228 KB |
Output is correct |
2 |
Correct |
176 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 |
179 ms |
7416 KB |
Output is correct |
2 |
Correct |
173 ms |
6776 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 |
182 ms |
7548 KB |
Output is correct |
2 |
Correct |
175 ms |
6920 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
173 ms |
6784 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
2696 KB |
Output is correct |
2 |
Correct |
182 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 |
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 |
175 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 |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
3192 KB |
Output is correct |
2 |
Correct |
176 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 |
82 ms |
3448 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |