#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];
bool f[N][N][N], dp[N][N];
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++)
for (int j = 0; j < N; j++) f[v][i][j] = 0;
for (int i = 0; i < k; i++) f[v][i][1] = 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)
{
memset(dp, 0, sizeof(dp));
for (int i = 0; i < k; i++)
for (int j = 0; j <= k; j++)
if (f[v][i][j])
{
for (int u = i + j; u < k; u++)
for (int kl = 0; kl + j <= k; kl++)
if (f[it][u][kl]) dp[i][kl + j] = 1;
}
for (int i = 0; i < k; i++)
for (int j = 0; j <= k; j++) f[v][i][j] = dp[i][j];
}
}
for (int i = 0; i < h[v]; i++) f[v][i][1] = 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++)
for (int u = 0; u < N; u++) f[i][j][u] = 1;
dfs(1, -1);
for (int j = 0; j <= k; j++)
if (f[1][0][j]) {cout << "DA" << endl; exit(0);}
cout << "NE" << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
65528 KB |
Output is correct |
2 |
Correct |
79 ms |
65528 KB |
Output is correct |
3 |
Correct |
99 ms |
65528 KB |
Output is correct |
4 |
Execution timed out |
1094 ms |
65528 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
65528 KB |
Output is correct |
2 |
Correct |
74 ms |
65528 KB |
Output is correct |
3 |
Correct |
107 ms |
65528 KB |
Output is correct |
4 |
Correct |
137 ms |
65528 KB |
Output is correct |
5 |
Incorrect |
77 ms |
65528 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
65656 KB |
Output is correct |
2 |
Correct |
74 ms |
65528 KB |
Output is correct |
3 |
Correct |
103 ms |
65528 KB |
Output is correct |
4 |
Correct |
205 ms |
65528 KB |
Output is correct |
5 |
Incorrect |
73 ms |
65528 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
65528 KB |
Output is correct |
2 |
Correct |
78 ms |
65528 KB |
Output is correct |
3 |
Correct |
112 ms |
65528 KB |
Output is correct |
4 |
Execution timed out |
1029 ms |
65656 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
65656 KB |
Output is correct |
2 |
Correct |
73 ms |
65528 KB |
Output is correct |
3 |
Correct |
102 ms |
65528 KB |
Output is correct |
4 |
Correct |
367 ms |
65528 KB |
Output is correct |
5 |
Incorrect |
77 ms |
65504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
65532 KB |
Output is correct |
2 |
Correct |
73 ms |
65528 KB |
Output is correct |
3 |
Correct |
108 ms |
65528 KB |
Output is correct |
4 |
Execution timed out |
1098 ms |
65528 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
65528 KB |
Output is correct |
2 |
Correct |
77 ms |
65528 KB |
Output is correct |
3 |
Correct |
117 ms |
65528 KB |
Output is correct |
4 |
Execution timed out |
1096 ms |
65528 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
65528 KB |
Output is correct |
2 |
Correct |
77 ms |
65504 KB |
Output is correct |
3 |
Correct |
112 ms |
65504 KB |
Output is correct |
4 |
Execution timed out |
1095 ms |
65528 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
65528 KB |
Output is correct |
2 |
Correct |
76 ms |
65528 KB |
Output is correct |
3 |
Correct |
108 ms |
65528 KB |
Output is correct |
4 |
Correct |
557 ms |
65528 KB |
Output is correct |
5 |
Incorrect |
73 ms |
65528 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
65528 KB |
Output is correct |
2 |
Correct |
79 ms |
65532 KB |
Output is correct |
3 |
Correct |
102 ms |
65540 KB |
Output is correct |
4 |
Correct |
189 ms |
65528 KB |
Output is correct |
5 |
Incorrect |
72 ms |
65528 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |