#include <bits/stdc++.h>
using namespace std;
const int N = 405;
vector<int> adj[N];
int par[N], dep[N], t;
array<int, 2> v[N];
int n, k;
vector<int> gud[N];
void dfs(int i, int p, int d) {
for (auto nxt : adj[i]) {
if (nxt == p) continue;
dfs(nxt, i, d + 1);
v[i][0] = min(v[i][0], v[nxt][0]);
v[i][1] = max(v[i][1], v[nxt][1]);
}
dep[i] = d;
if (d == k) {
v[i][0] = min(v[i][0], t);
v[i][1] = max(v[i][1], t);
t++;
}
if (v[i][0] != n + 1) {
par[i] = p;
gud[d].push_back(i);
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
if (n <= k * k) {
cout << "DA\n";
return 0;
}
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
v[i] = {n + 1, -1};
}
dfs(1, 0, 0);
for (int i = 1; i <= n; i++) adj[i].clear();
for (int i = 1; i <= n; i++) {
if (!par[i]) continue;
adj[par[i]].push_back(i);
}
// for (int i = 1; i <= k; i++) {
// for (auto j : gud[i]) {
// cout << v[j][0] << ", " << v[j][1] << '\n';
// }
// cout << '\n';
// }
int m = 1 << k, dp[m];
dp[0] = -1;
for (int msk = 1; msk < m; msk++) {
dp[msk] = -1;
for (int j = 1; j <= k; j++) {
if (!((msk >> (j - 1)) & 1)) continue;
for (auto i : gud[j]) {
if (v[i][0] <= dp[msk ^ (1 << (j - 1))] + 1) {
dp[msk] = max(dp[msk], v[i][1]);
}
}
}
}
if (dp[m - 1] == t - 1) {
cout << "DA\n";
} else {
cout << "NE\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
45 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
856 KB |
Output is correct |
2 |
Correct |
43 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
43 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
984 KB |
Output is correct |
2 |
Correct |
45 ms |
1016 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
604 KB |
Output is correct |
2 |
Correct |
46 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
996 KB |
Output is correct |
2 |
Correct |
45 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
860 KB |
Output is correct |
2 |
Correct |
42 ms |
992 KB |
Output is correct |
3 |
Correct |
1 ms |
548 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
860 KB |
Output is correct |
2 |
Correct |
42 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
480 KB |
Output is correct |
5 |
Correct |
43 ms |
860 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
620 KB |
Output is correct |
2 |
Correct |
45 ms |
992 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
45 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
604 KB |
Output is correct |
2 |
Correct |
54 ms |
868 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
23 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
480 KB |
Output is correct |