#include<bits/stdc++.h>
#define int long long
using namespace std ;
const int maxn = 405 ;
int n, tin[maxn], tout[maxn], timer, k, nivel[maxn], dp[(1<<14)][maxn] ;
vector<int> grafo[maxn], vec[maxn] ;
void dfs(int v, int p){
if(nivel[v] >= 0) vec[nivel[v]].push_back(v) ;
tin[v] = timer + 1 ;
for(auto a : grafo[v]){
if(a == p) continue ;
nivel[a] = nivel[v] + 1 ;
if(nivel[a] < k) dfs(a, v) ;
}
if(nivel[v] == k-1) timer++ ;
tout[v] = timer ;
}
int32_t main(){
cin >> n >> k ;
for(int i = 1 ; i < n ; i++){
int u, v ;
cin >> u >> v ; u--, v-- ;
grafo[u].push_back(v) ; grafo[v].push_back(u) ;
}
if(k*k >= n){
cout << "DA\n" ; exit(0) ;
}
nivel[0] = -1 ;
dfs(0, 0) ;
for(int i = 0 ; i < (1<<k) ; i++) dp[i][0] = 1 ;
for(int mask = 1 ; mask < (1<<k) ; mask++){
for(int i = 0 ; i < k ; i++){
if(!(mask&(1<<i))) continue ;
for(auto at : vec[i]){
if(dp[mask^(1<<i)][tin[at]-1]) dp[mask][tout[at]] = 1 ;
}
}
}
bool flag = 0 ;
for(int i = 0 ; i < (1<<k) ; i++){
if(dp[i][timer]){
cout << "DA\n" ; exit(0) ;
}
}
cout << "NE\n" ;
}
Compilation message
burza.cpp: In function 'int32_t main()':
burza.cpp:62:10: warning: unused variable 'flag' [-Wunused-variable]
62 | bool flag = 0 ;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
52172 KB |
Output is correct |
2 |
Runtime error |
70 ms |
105764 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
67 ms |
105776 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
68 ms |
105800 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
68 ms |
105796 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
67 ms |
105780 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
69 ms |
105812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
69 ms |
105844 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
74 ms |
105696 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
52180 KB |
Output is correct |
2 |
Runtime error |
83 ms |
105824 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
78 ms |
105816 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |