/**
* author: wxhtzdy
* created: 11.08.2022 19:27:55
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
--u; --v;
g[u].push_back(v);
g[v].push_back(u);
}
if (k >= 20) {
cout << "DA" << '\n';
return 0;
}
vector<int> dep(n);
vector<int> dfn(n);
vector<int> dfo(n);
int T = 0;
vector<vector<int>> par(n);
function<void(int, int)> Dfs = [&](int v, int pr) {
dfn[v] = ++T;
for (int p : par[pr]) {
par[v].push_back(p);
}
par[v].push_back(v);
for (int u : g[v]) {
if(u == pr) {
continue;
}
dep[u] = dep[v] + 1;
Dfs(u, v);
}
dfo[v] = T;
};
Dfs(0, 0);
vector<vector<int>> at(n);
for (int i = 0; i < n; i++) {
at[dep[i]].push_back(i);
}
auto isPar = [&](int v, int u) {
return dfn[v] <= dfn[u] && dfo[u] <= dfo[v];
};
int sz = (int) at[k].size();
vector<vector<bool>> dp(sz + 1, vector<bool>(1 << (k + 1)));
dp[0][0] = true;
for (int i = 0; i < sz; i++) {
int v = at[k][i];
int ptr = sz - 1;
for (int s = 0; s < (1 << (k + 1)); s++) {
for (int idx : par[v]) {
if (idx == 0) {
continue;
}
if (s >> dep[idx] & 1) {
continue;
}
while (!isPar(idx, at[k][ptr])) {
assert(ptr > i);
ptr -= 1;
}
if (dp[i][s]) {
dp[ptr + 1][s | (1 << dep[idx])] = true;
}
}
}
}
bool ans = false;
for (int i = 0; i < (1 << (k + 1)); i++) {
ans = (ans | dp[sz][i]);
}
cout << (ans ? "DA" : "NE") << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
3028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
3028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
591 ms |
1388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
2516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
3156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
3028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
434 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
640 KB |
Output is correct |
2 |
Execution timed out |
1080 ms |
3284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
598 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |