#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n,k;
vector<vector<int>> edges;
vector<int> depth;
vector<int> parents;
vector<vector<int>> depths(400);
int maxDepth(int i, int dpth) {
depth[i]=dpth;
int maxD = dpth;
for(int j = 0; j < edges[i].size(); j++) {
int l = edges[i][j];
if(depth[l]!=-1) continue;
if(dpth==k) {
edges[i][j]=-1;
} else {
if(maxDepth(l, dpth+1)!=k) {
edges[i][j]=-1;
} else {
parents[l]=i;
maxD=k;
}
}
}
if(maxD==k) {
depths[dpth].push_back(i);
}
return maxD;
}
struct state {
int level;
vector<int> mustConsider;
state(int level, vector<int> unaccessible) {
this->mustConsider = unaccessible;
this->level = level;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
if(k * k>n) {
cout << "DA" << endl;
return 0;
}
edges=vector<vector<int>>(n);
depth=vector<int>(n, -1);
parents=vector<int>(n, -1);
depth[0]=0;
for(int i = 1; i < n; i++) {
int a,b;
cin >> a >> b;
edges[a-1].push_back(b-1);
edges[b-1].push_back(a-1);
}
maxDepth(0, 0);
/*
for(int i = 0; i < n; i++) {
cout << i << " " << depth[i] << " " << parents[i] << endl;
for(int j: depths[i]) {
cout << j << " ";
}
cout << endl;
for(int j: edges[i]) {
cout << j << " ";
}
cout << endl;
}
*/
deque<vector<int>> q;
q.push_back(vector<int>(1,0));
set<vector<int>> vis;
while(q.size()) {
vector<int> s = q.front();
q.pop_front();
if(s.size()==0) {
cout << "DA" << endl;
return 0;
}
int remain = k-depth[s[0]];
vector<int> next;
for(int i: s) {
for(int j: edges[i]) {
if(j==parents[i]) continue;
next.push_back(j);
}
}
if(next.size()>remain) {
continue;
}
for(int i = 0; i < next.size(); i++) {
swap(next[i], next.back());
vector<int> temp = next;
temp.pop_back();
sort(begin(temp), end(temp));
if(!vis.count(temp)) {
q.push_back(temp);
vis.insert(temp);
}
swap(next[i], next.back());
}
}
cout << "NE" << endl;
}
Compilation message
burza.cpp: In function 'int maxDepth(int, int)':
burza.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int j = 0; j < edges[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
burza.cpp: In function 'int main()':
burza.cpp:90:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
90 | if(next.size()>remain) {
| ~~~~~~~~~~~^~~~~~~
burza.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i = 0; i < next.size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
10 ms |
1096 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
648 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |