#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int n, k;
vector<vector<int>> gp;
vector<int> d;
vector<bool> lav;
vector<int> l, r;
int last;
void dfs(int u = 0, int p = -1) {
if (p == -1) d[u] = 0;
else d[u] = d[p] + 1;
if (d[u] == k) {
lav[u] = true;
l[u] = last;
r[u] = last;
last++;
return;
}
for (int v : gp[u]) {
if (v == p) continue;
dfs(v, u);
lav[u] = (lav[u] | lav[v]);
r[u] = max(r[u], r[v]);
l[u] = min(l[u], l[v]);
}
}
void solve() {
cin >> n >> k;
gp = vector<vector<int>>(n);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--, v--;
gp[u].push_back(v);
gp[v].push_back(u);
}
if (k > 10) {
cout << "DA" << endl;
return;
}
d = vector<int>(n);
l = vector<int>(n, 2e9);
r = vector<int>(n, -2e9);
lav = vector<bool>(n);
last = 0;
dfs();
// for (int i = 0; i < n; i++) {
// if (!lav[i]) continue;
// cout << i+1 << " " << l[i] << "-" << r[i] << endl;
// }
// cout << "VERJ" << endl;
int lbyr[k][last];
for (int i = 0; i < k; i++) {
for (int j = 0; j < last; j++) {
lbyr[i][j] = -1;
}
}
for (int i = 1; i < n; i++) {
if (!lav[i]) continue;
lbyr[d[i]-1][r[i]] = l[i];
}
bool ans = false;
bool dp[1<<k][last]{};
for (int s = 1; s < (1<<k); s++) {
for (int i = 0; i < last; i++) {
dp[s][i] = false;
for (int j = 0; j < k; j++) {
if (!(s & (1<<j))) continue;
if (lbyr[j][i] == -1) continue;
if (lbyr[j][i] == 0) {
dp[s][i] = true;
break;
}
if (dp[s^(1<<j)][lbyr[j][i]-1]) {
dp[s][i] = true;
break;
}
}
if (dp[s][i] && i == last-1) {
ans = true;
}
}
}
if (ans) cout << "DA" << endl;
else cout << "NE" << endl;
}
int main() {
int t = 1;
//cin >> t;
while (t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |