#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int NMAX = 401;
const int inf = 1e9 + 1;
vector <vector <int> > g(NMAX);
bool dp[(1 << 20) - 1][NMAX];
int timer = 1;
int l[NMAX], r[NMAX];
int k;
void dfs(int v, int depth, int e = -1){
if(depth == k){
// cout << v << ' ';
l[v] = r[v] = timer;
timer++;
return;
}
for(int to : g[v]){
if(to == e) continue;
dfs(to, depth + 1, v);
l[v] = min(l[v], l[to]);
r[v] = max(r[v], r[to]);
}
}
void DFS(int v, int depth = -1, int e = -1){
if(l[v] == inf) return;
if(depth != -1){
for(int mask = 0; mask < (1 << (k)); mask++){
if(mask & (1 << depth)) continue;
if(dp[mask][l[v] - 1]) dp[mask + (1 << depth)][r[v]] = true;
}}
for(int to : g[v]){
if(to == e) continue;
DFS(to, depth + 1, v);
}
}
int main(){
int n; cin >> n;
cin >> k;
for(int i = 1; i < n; i++){
int u , v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1; i <= n; i++){
l[i] = inf;
r[i] = 0;
}
if(k * k > n){
cout << "DA\n";
return 0;
}
for(int i = 0; i < (1 << k); i++) dp[i][0] = true;
dfs(1, 0);
/*for(int i = 1; i <= n; i++){
cout << l[i] << ' ' << r[i] << "\n";
}*/
DFS(1);
/*for(int i = 1; i < (1 << k); i++){
for(int j = 0; j < timer; j++){
dp[i][j] ? cout << 1 : cout << 0;
cout << ' ';
}
cout << "\n";
}*/
dp[(1 << k) - 1][timer - 1] ? cout << "DA" : cout << "NE";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
6740 KB |
Output is correct |
2 |
Correct |
237 ms |
51740 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
358 ms |
51744 KB |
Output is correct |
2 |
Correct |
204 ms |
51860 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
268 ms |
51748 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
51736 KB |
Output is correct |
2 |
Correct |
235 ms |
51808 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
13140 KB |
Output is correct |
2 |
Correct |
223 ms |
51668 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
51736 KB |
Output is correct |
2 |
Correct |
195 ms |
51736 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
51740 KB |
Output is correct |
2 |
Correct |
209 ms |
51788 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
51736 KB |
Output is correct |
2 |
Correct |
212 ms |
51748 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
210 ms |
51644 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
13180 KB |
Output is correct |
2 |
Correct |
247 ms |
51736 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
6760 KB |
Output is correct |
2 |
Correct |
294 ms |
51756 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
25940 KB |
Output is correct |
2 |
Correct |
219 ms |
51748 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
77 ms |
25940 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |