#include <bits/stdc++.h>
using namespace std;
#define N 405
#define M 19
int l[N], r[N], dp[(1 << M) + 5], n, cnt, dep[N], k;
vector<int> adj[N];
void dfs(int u, int p){
if (dep[u] == k){
l[u] = r[u] = ++cnt;
return;
}
for (auto x : adj[u]){
if (x == p) continue;
dep[x] = dep[u] + 1;
dfs(x, u);
l[u] = min(l[u], l[x]);
r[u] = max(r[u], r[x]);
}
}
int getbit(int msk, int pos){
return (msk >> pos) & 1;
}
int offbit(int msk, int pos){
return (msk & (~(1 << pos)));
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> k;
for (int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if (k * k >= n){
cout << "DA";
return 0;
}
for (int i = 1; i <= n; i++) l[i] = 1e9, r[i] = 0;
dfs(1, 0);
for (int msk = 1; msk < 1 << k; msk++){
for (int i = 1; i <= n; i++){
if (!dep[i] || !getbit(msk, dep[i] - 1)) continue;
int lstmsk = offbit(msk, dep[i] - 1);
if (dp[lstmsk] + 1 >= l[i]) dp[msk] = max({dp[msk], r[i], dp[lstmsk]});
}
}
if (dp[(1 << k) - 1] == cnt) cout << "DA";
else cout << "NE";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
520 KB |
Output is correct |
2 |
Correct |
240 ms |
1204 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 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 |
226 ms |
872 KB |
Output is correct |
2 |
Correct |
230 ms |
1148 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
235 ms |
852 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
248 ms |
828 KB |
Output is correct |
2 |
Correct |
233 ms |
848 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
760 KB |
Output is correct |
2 |
Correct |
234 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
472 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
235 ms |
1088 KB |
Output is correct |
2 |
Correct |
233 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
234 ms |
948 KB |
Output is correct |
2 |
Correct |
226 ms |
848 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 |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
1220 KB |
Output is correct |
2 |
Correct |
224 ms |
828 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
226 ms |
1052 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
572 KB |
Output is correct |
2 |
Correct |
239 ms |
800 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
348 KB |
Output is correct |
2 |
Correct |
237 ms |
812 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
600 KB |
Output is correct |
2 |
Correct |
226 ms |
796 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
100 ms |
636 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |