// -----------------------------------------------------------------------------------------------------
// | |
// | ngungungu ngungungu ngu ngu ngungu ngungungu ngungungu |
// | ngu ngu nguu ngu ngu ngu ngu nguuu nguuu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu nguuu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu nguuu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu ngungungu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu nguuu ngu ngu ngu ngu |
// | ngu ngu nguu ngu ngu ngu ngu ngu ngu nguuu ngu ngu ngu ngu ngu |
// | ngungungu ngungungu ngu ngu ngu ngu ngu ngu ngu ngu |
// | |
// -----------------------------------------------------------------------------------------------------
// ONLINE_JUDGE
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = (a) , _b = (b) ; i <= _b ;i ++)
#define F first
#define S second
//#define int long long
#define pii pair<int, int>
#define piii pair<int, pair<int, int>>
#define piiii pair<pair<int, int>, pair<int, int>>
#define minimize(x,y) x = (x > y ? y : x)
#define maximize(x,y) x = (x < y ? y : x)
using namespace std;
const int maxn = 409;
const int mod = 1e9 + 7;
int n, k;
vector<int> a[maxn];
int h[maxn], maxf[maxn];
int tin[maxn], tout[maxn], timef;
vector<int> v;
bool dp[maxn][(1 << 20) + 1];
void pre(int x, int pX){
maxf[x] = h[x];
if(h[x] == k) return;
for(auto y : a[x]){
if(y != pX){
h[y] = h[x] + 1;
pre(y, x);
maximize(maxf[x], maxf[y]);
}
}
}
void dfs(int x, int pX){
tin[x] = timef ++;
v.push_back(x);
for(auto y : a[x]){
if(y != pX && maxf[y] == k){
dfs(y, x);
}
}
tout[x] = timef;
}
int32_t main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
f(i, 1, n - 1){
int u, v;
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
}
if(k * k >= n){
cout << "DA";
return 0;
}
pre(1, 0);
dfs(1, 0);
f(i, 0, (1 << 20) - 1) dp[timef][i] = 1;
for(int i = timef - 1;i >= 0;i --){
f(j, 0, (1 << k) - 1){
int x = v[i];
if(h[x] < k){
dp[i][j] = dp[i + 1][j];
if(dp[i][j]) continue;
}
if((j >> h[x]) & 1) continue;
dp[i][j] = dp[tout[x]][j | (1 << h[x])];
}
}
cout << (dp[1][0] ? "DA" : "NE");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
299836 KB |
Output is correct |
2 |
Correct |
109 ms |
384340 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
35 ms |
369688 KB |
Output is correct |
6 |
Incorrect |
7 ms |
68188 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
367768 KB |
Output is correct |
2 |
Correct |
100 ms |
367696 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
100 ms |
369948 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
369836 KB |
Output is correct |
2 |
Correct |
100 ms |
367688 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
295792 KB |
Output is correct |
6 |
Correct |
8 ms |
82520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
359580 KB |
Output is correct |
2 |
Correct |
104 ms |
386292 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
25 ms |
252892 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
353360 KB |
Output is correct |
2 |
Correct |
98 ms |
365648 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Incorrect |
36 ms |
375892 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
371812 KB |
Output is correct |
2 |
Correct |
96 ms |
361668 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
34 ms |
342956 KB |
Output is correct |
6 |
Correct |
22 ms |
221892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
376116 KB |
Output is correct |
2 |
Correct |
110 ms |
363620 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
99 ms |
363756 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
318544 KB |
Output is correct |
2 |
Correct |
100 ms |
377936 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
21 ms |
222056 KB |
Output is correct |
6 |
Correct |
37 ms |
386132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
265296 KB |
Output is correct |
2 |
Correct |
107 ms |
378144 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
22 ms |
228188 KB |
Output is correct |
6 |
Correct |
33 ms |
345408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
314392 KB |
Output is correct |
2 |
Correct |
102 ms |
379988 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
59 ms |
320596 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |