#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int n, k, p[401],md[401];
vi graph[401];
vi depth_nodes[401];
void dfs(int u, int d) {
md[u]=d;
trav(v, graph[u]) if (v != p[u]) {
p[v] = u;
dfs(v, d + 1);
md[u]=max(md[u],md[v]);
}
if(md[u]>=k)depth_nodes[d].pb(u);
}
set<vector<int>> memo[401];
void dp(int depth, vi blocked) {
bool all_blocked = 1;
trav(node, blocked) all_blocked &= node;
if (all_blocked) {
cout << "DA" << endl;
exit(0);
}
if(depth>=k)return;
if (memo[depth].count(blocked)) return;
vi next;
int pos = 0;
trav(u, depth_nodes[depth]) {
trav(v, graph[u])if(p[u]!=v&&md[v]>=k) next.pb(blocked[pos]);
++pos;
}
if(next.empty()){
cout << "DA" << endl;
exit(0);
}
rep(i,0,sz(next)){
if(next[i])continue;
if(!depth&&i)continue;
next[i]=1;
dp(depth+1,next);
next[i]=0;
}
memo[depth].insert(blocked);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n >> k;
rep(i, 0, n - 1) {
int u, v;
cin >> u >> v;
graph[--u].pb(--v);
graph[v].pb(u);
}
dfs(0, 0);
dp(0, vi(sz(depth_nodes[0]), 0));
cout << "NE" << endl;
return 0;
}
Compilation message
burza.cpp: In function 'void dp(int, vi)':
burza.cpp:5:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(i, a, b) for (int i = (a); i < (b); ++i)
| ^
burza.cpp:71:5: note: in expansion of macro 'rep'
71 | rep(i,0,sz(next)){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1484 KB |
Output is correct |
2 |
Correct |
272 ms |
9536 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
62 ms |
836 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
9548 KB |
Output is correct |
2 |
Correct |
255 ms |
9564 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
81 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
256 ms |
9540 KB |
Output is correct |
2 |
Correct |
272 ms |
9600 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Execution timed out |
1090 ms |
13816 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
2580 KB |
Output is correct |
2 |
Correct |
260 ms |
9592 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
38 ms |
1116 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
9492 KB |
Output is correct |
2 |
Correct |
252 ms |
9524 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
12 ms |
652 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
9480 KB |
Output is correct |
2 |
Correct |
265 ms |
9580 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
7 ms |
460 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
260 ms |
9780 KB |
Output is correct |
2 |
Correct |
261 ms |
9480 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
237 ms |
4292 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
2648 KB |
Output is correct |
2 |
Correct |
254 ms |
9600 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Incorrect |
32 ms |
952 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1392 KB |
Output is correct |
2 |
Correct |
256 ms |
9592 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
17 ms |
588 KB |
Output is correct |
6 |
Correct |
419 ms |
5448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
4936 KB |
Output is correct |
2 |
Correct |
269 ms |
9532 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |