#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 403, mod = 1e9 + 7; //!
int t, dp[1 << 20], h[N], tmin[N], timer, tmout[N], p[N], P[N][N];
vector<int> v, V[N];
int n, k;
void dfs(int u) {
h[u] = h[p[u]] + 1;
if(h[u] == k) {
v.push_back(u);
P[++timer][h[u] - 2] = u;
tmin[u] = tmout[u] = timer;
return;
}
tmin[u] = n + 1;
for(int i = 0; i < V[u].size(); i++) {
if(V[u][i] == p[u]) continue;
p[V[u][i]] = u;
dfs(V[u][i]);
tmin[u] = min(tmin[u], tmin[V[u][i]]);
}
P[tmin[u]][h[u] - 2] = u;
tmout[u] = timer;
}
main() {
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n >> k;
++k;
if(k > 20) {
cout << "DA";
return 0;
}
for(int i = 2; i <= n; i++) {
int u, v;
cin >> u >> v;
V[u].push_back(v);
V[v].push_back(u);
}
dfs(1);
dp[0] = 1;
bool ans = 0;
for(int i = 0; i < (1 << k); i++) {
ans |= (dp[i] == timer + 1);
if(ans) break;
for(int j = 0; j < k; j++) {
if(!(i & (1 << j)) && P[dp[i]][j]) {
dp[i ^ (1 << j)] = max(dp[i ^ (1 << j)], tmout[P[dp[i]][j]] + 1);
}
}
}
cout << (ans ? "DA" : "NE");
}
Compilation message
burza.cpp: In function 'void dfs(int)':
burza.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = 0; i < V[u].size(); i++) {
| ~~^~~~~~~~~~~~~
burza.cpp: At global scope:
burza.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
29 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
516 KB |
Output is correct |
2 |
Correct |
15 ms |
980 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
992 KB |
Output is correct |
2 |
Correct |
15 ms |
1008 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
976 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
988 KB |
Output is correct |
2 |
Correct |
16 ms |
1000 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
15 ms |
952 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
980 KB |
Output is correct |
2 |
Correct |
18 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
980 KB |
Output is correct |
2 |
Correct |
21 ms |
992 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1008 KB |
Output is correct |
2 |
Correct |
18 ms |
968 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 KB |
Output is correct |
2 |
Correct |
16 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
15 ms |
1024 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
596 KB |
Output is correct |
2 |
Correct |
16 ms |
1008 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |