#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
#define FIRSTBIT(x) __builtin_ctzll(x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* */
template<class T>
bool minimize(T &a, const T &b) {
if(a > b) {a = b; return 1;}
return 0;
}
template<class T>
bool maximize(T &a, const T &b) {
if(a < b) {a = b; return 1;}
return 0;
}
/* */
/* CODE BELOW */
const int N = 400 + 7, M = 20;
const int oo = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, k;
int _dp[MASK(M)];
vector<int> adj[N];
int jump[N][M+1], h[N];
int in[N], out[N], cnt = 0;
void dfs(int u = 1, int p = -1) {
if(h[u] == k) in[u] = out[u] = ++cnt;
else in[u] = oo, out[u] = -oo;
if(h[u]<k) for(int v:adj[u]) if(v!=p) {
h[v] = h[u] + 1;
dfs(v, u);
minimize(in[u], in[v]);
maximize(out[u], out[v]);
}
if(in[u]!=oo) maximize(jump[in[u]][h[u]], out[u]);
}
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d%d", &n, &k);
if(k*k>=n) {printf("DA"); return 0;}
int u, v;
for(int i=1;i<n;i++) {
scanf("%d%d", &u, &v);
adj[u].pb(v), adj[v].pb(u);
}
dfs();
if(in[1] == oo) {printf("DA"); return 0;}
memset(_dp, -1, sizeof _dp); _dp[0] = 0;
for(int i=0;i<MASK(k);i++) if(_dp[i]!=-1) {
if(_dp[i] == out[1]) {
printf("DA"); return 0;
}
for(int j=(MASK(k)-1)^i;j>0;j-=j&-j) {
int pos = FIRSTBIT(j&-j);
maximize(_dp[i|MASK(pos)], jump[_dp[i]+1][pos+1]);
}
}
printf("NE");
return 0;
}
Compilation message
burza.cpp: In function 'int main()':
burza.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
burza.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
6 ms |
4428 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
4428 KB |
Output is correct |
6 |
Correct |
2 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4440 KB |
Output is correct |
2 |
Correct |
5 ms |
4428 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
6 ms |
4428 KB |
Output is correct |
6 |
Correct |
2 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4400 KB |
Output is correct |
2 |
Correct |
5 ms |
4428 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
4428 KB |
Output is correct |
6 |
Correct |
3 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
7 ms |
4428 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
4416 KB |
Output is correct |
6 |
Correct |
2 ms |
4416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4428 KB |
Output is correct |
2 |
Correct |
6 ms |
4432 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
4428 KB |
Output is correct |
6 |
Correct |
3 ms |
4404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4428 KB |
Output is correct |
2 |
Correct |
5 ms |
4436 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
4 ms |
4356 KB |
Output is correct |
6 |
Correct |
2 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4420 KB |
Output is correct |
2 |
Correct |
5 ms |
4428 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
6 ms |
4428 KB |
Output is correct |
6 |
Correct |
3 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
8 ms |
4428 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
4428 KB |
Output is correct |
6 |
Correct |
2 ms |
4428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4428 KB |
Output is correct |
2 |
Correct |
5 ms |
4428 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
2 ms |
4428 KB |
Output is correct |
6 |
Correct |
3 ms |
4412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4428 KB |
Output is correct |
2 |
Correct |
7 ms |
4428 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
3 ms |
4428 KB |
Output is correct |
6 |
Correct |
2 ms |
4412 KB |
Output is correct |