#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 405
#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[N];
int n, k, h[N], mx_h[N], kl[N][N], koler[N];
bool f[N][N], dp[N], dpr[N][(1 << 14)];
void dfs(int v, int p)
{
if (p != -1) h[v] = h[p] + 1;
mx_h[v] = h[v];
if (h[v] == k)
{
for (int i = 0; i < N; i++) {kl[v][i] = 1e9; f[v][i] = 0;}
for (int i = 0; i < k; i++) {kl[v][i] = 1; f[v][i] = 1;}
return;
}
for (auto it : g[v])
{
if (it == p) continue;
dfs(it, v);
mx_h[v] = max(mx_h[v], mx_h[it]);
if (mx_h[it] >= k)
{
for (int i = 0; i < N; i++) {dp[i] = 0; koler[i] = 1e9;}
for (int i = 0; i < k; i++)
{
if (!f[v][i]) continue;
for (int u = i + kl[v][i]; u < k; u++)
if (f[it][u]) {koler[i] = min(koler[i], kl[v][i] + kl[it][u]); dp[i] = 1;}
}
for (int i = 0; i < N; i++) {kl[v][i] = koler[i]; f[v][i] = dp[i];}
}
}
for (int i = 0; i < h[v]; i++) if (!f[v][i] || kl[v][i] > 1) {kl[v][i] = 1; f[v][i] = 1;}
}
void rec(int v, int p)
{
if (h[v] == k) {for (int i = 0; i < k; i++) dpr[v][(1 << i)] = 1; return;}
for (auto it : g[v])
if (it != p && mx_h[it] >= k)
{
rec(it, v);
bool fr[(1 << 14)];
memset(fr, 0, sizeof(fr));
for (int msk = 0; msk < (1 << k); msk++)
{
if (!dpr[v][msk]) continue;
if (h[it] == k)
{
for (int i = 0; i < k; i++)
if (((1 << i) & msk) == 0) fr[msk | (1 << i)] = 1;
}
else
for (int smsk = 0; smsk < (1 << k); smsk++)
{
if (!dpr[it][smsk] || (smsk & msk) != 0) continue;
fr[smsk | msk] = 1;
}
}
for (int msk = 0; msk < (1 << k); msk++) dpr[v][msk] = fr[msk];
}
for (int i = 0; i < h[v]; i++) dpr[v][(1 << i)] = 1;
}
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;
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {kl[i][j] = 0; f[i][j] = 1;}
dfs(1, -1);
bool gd = 0;
if (k <= 14)
{
memset(dpr, 1, sizeof(dpr));
rec(1, -1);
for (int msk = 0; msk < (1 << k); msk++) gd |= dpr[1][msk];
}
if (f[1][0] || gd) {cout << "DA" << endl; exit(0);}
cout << "NE" << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
7680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
6 ms |
1152 KB |
Output is correct |
5 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
6 ms |
1152 KB |
Output is correct |
5 |
Correct |
12 ms |
7808 KB |
Output is correct |
6 |
Correct |
8 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
8 ms |
1152 KB |
Output is correct |
5 |
Correct |
9 ms |
7680 KB |
Output is correct |
6 |
Correct |
9 ms |
7680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
6 ms |
1152 KB |
Output is correct |
5 |
Correct |
13 ms |
7808 KB |
Output is correct |
6 |
Correct |
9 ms |
7680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
8 ms |
1152 KB |
Output is correct |
5 |
Correct |
11 ms |
7808 KB |
Output is correct |
6 |
Correct |
9 ms |
7680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
9 ms |
1152 KB |
Output is correct |
5 |
Incorrect |
6 ms |
1152 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
8 ms |
1280 KB |
Output is correct |
5 |
Correct |
9 ms |
7680 KB |
Output is correct |
6 |
Correct |
9 ms |
7808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
7908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
6 ms |
1152 KB |
Output is correct |
5 |
Incorrect |
5 ms |
1152 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |