#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 2> a2;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vector <int> g[401], vr;
int h[401], n, k, mxh[401], in[401], out[401];
bool f[401][(1 << 19)];
void rec(int v, int p)
{
if (p != -1) h[v] = h[p] + 1;
mxh[v] = h[v];
if (h[v] == k) return;
for (auto it : g[v])
{
if (it == p) continue;
rec(it, v);
mxh[v] = max(mxh[v], mxh[it]);
}
}
void dfs(int v, int p)
{
in[v] = sz(vr);
vr.pb(v);
for (auto it : g[v])
{
if (it == p || mxh[it] != k) continue;
dfs(it, v);
}
out[v] = sz(vr);
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
if (k >= 20) {cout << "DA" << endl; exit(0);}
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
rec(1, -1);
dfs(1, -1);
for (int i = 0; i < (1 << 19); i++) f[sz(vr)][i] = 1;
for (int i = sz(vr) - 1; i >= 0; i--)
for (int msk = 0; msk < (1 << k); msk++)
{
int v = vr[i];
if (h[v] < k)
{
f[i][msk] = f[i + 1][msk];
if (f[i][msk]) continue;
}
if ((1 << h[v]) & msk) continue;
f[i][msk] = f[out[v]][msk | (1 << h[v])];
}
if (!f[1][0]) cout << "NE" << endl;
else cout << "DA" << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
7040 KB |
Output is correct |
2 |
Correct |
100 ms |
50424 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
48248 KB |
Output is correct |
2 |
Correct |
101 ms |
48248 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
96 ms |
48504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
48504 KB |
Output is correct |
2 |
Correct |
93 ms |
48380 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
2304 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
13824 KB |
Output is correct |
2 |
Correct |
100 ms |
50696 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
8 ms |
2048 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
46328 KB |
Output is correct |
2 |
Correct |
95 ms |
48120 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
48760 KB |
Output is correct |
2 |
Correct |
95 ms |
47480 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
2560 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
49272 KB |
Output is correct |
2 |
Correct |
97 ms |
47864 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
91 ms |
47736 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12288 KB |
Output is correct |
2 |
Correct |
97 ms |
49724 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
1920 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
6272 KB |
Output is correct |
2 |
Correct |
105 ms |
49656 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
1920 KB |
Output is correct |
6 |
Correct |
7 ms |
2560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
22008 KB |
Output is correct |
2 |
Correct |
95 ms |
49912 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
45 ms |
22272 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |