#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> adj[402], q[402];
int n, k, st[402], dr[402], level[402], pz;
void dfs(int u, int p) {
if (u==p) return;
if (u) {
level[u]=level[p]+1;
}
if (level[u]==k-1) {
st[u]=pz++;
dr[u]=pz;
return;
}
st[u]=pz;
for (auto i : adj[u]) {
if (i!=p) dfs(i, u);
}
dr[u]=pz;
}
bool dp[402][(1<<20)];
bool solve() {
dp[0][0]=1;
for (int i = 1; i < n; i++) {
q[st[i]].push_back(i);
}
for (int i = 0; i < pz; i++) {
for (int j = 0; j < (1<<k); j++) {
if (!dp[i][j]) continue;
for (auto it : q[i]) {
if (!(j >> level[it] & 1)) {
dp[dr[it]][j | (1<<level[it])]=1;
}
}
}
}
for (int j = 0; j < (1<<k); j++) {
if (dp[pz][j]) return 1;
}
return 0;
}
int main() {
cin >> n >> k;
if (k*k >= n) {
cout << "DA\n";
return 0;
}
for (int i = 1; i < n; i++) {
int a, b; cin >> a >> b;
a--; b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
level[0]=-1;
dfs(0, -1);
cout << (solve() ? "DA\n" : "NE\n");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
852 KB |
Output is correct |
2 |
Correct |
38 ms |
2412 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
2696 KB |
Output is correct |
2 |
Correct |
41 ms |
2468 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
66 ms |
2920 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2808 KB |
Output is correct |
2 |
Correct |
44 ms |
2400 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1332 KB |
Output is correct |
2 |
Correct |
63 ms |
3292 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
2260 KB |
Output is correct |
2 |
Correct |
48 ms |
2836 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
2632 KB |
Output is correct |
2 |
Correct |
50 ms |
2764 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
2968 KB |
Output is correct |
2 |
Correct |
51 ms |
2740 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
61 ms |
3140 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1236 KB |
Output is correct |
2 |
Correct |
46 ms |
2612 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
724 KB |
Output is correct |
2 |
Correct |
63 ms |
3044 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1624 KB |
Output is correct |
2 |
Correct |
59 ms |
2948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
21 ms |
1580 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |