#include <bits/stdc++.h>
using namespace std;
#define YES "DA"
#define NO "NE"
vector<vector<int>> layers;
unordered_map<int, bitset<50>> coverage;
bitset<50> dfs(vector<vector<int>> &mp, int n, int p, int d, int k){
if(layers.size() == d)
layers.push_back(vector<int>());
if(d == k){
coverage[n] |= 1;
coverage[n] <<= layers[d].size();
}
layers[d].push_back(n);
for(int v : mp[n]){
if(v != p){
bitset<50> res = dfs(mp, v, n, d+1, k);
if(layers.size() > k && d < k)
coverage[n] |= res;
}
}
return coverage[n];
}
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<vector<int>> mp(n, vector<int>());
for(int i = 0; i < n-1; i++){
int u, v;
cin >> u >> v;
mp[--u].push_back(--v);
mp[v].push_back(u);
}
dfs(mp, 0, -1, 0, k);
if(layers.size() <= k)
cout << YES << "\n";
else{
unordered_set<bitset<50>> cur, prev = {bitset<50>()};
bool g = false;
for(int i = 1; i <= k; i++){
for(int v : layers[i]){
for(bitset<50> bs : prev){
if((coverage[v] & bs) == 0){
cur.insert(coverage[v] | bs);
if((coverage[v] | bs).count() == layers[k].size())
g = true;
}
}
}
swap(cur, prev);
cur.clear();
}
cout << (g ? YES : NO) << "\n";
}
}
Compilation message
burza.cpp: In function 'std::bitset<50> dfs(std::vector<std::vector<int> >&, int, int, int, int)':
burza.cpp:12:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
12 | if(layers.size() == d)
| ~~~~~~~~~~~~~~^~~~
burza.cpp:26:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
26 | if(layers.size() > k && d < k)
| ~~~~~~~~~~~~~~^~~
burza.cpp: In function 'int main()':
burza.cpp:54:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | if(layers.size() <= k)
| ~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
4080 KB |
Output is correct |
2 |
Correct |
20 ms |
2680 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
6784 KB |
Output is correct |
2 |
Correct |
50 ms |
5084 KB |
Output is correct |
3 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
20328 KB |
Output is correct |
2 |
Correct |
115 ms |
10240 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
852 KB |
Output is correct |
2 |
Correct |
75 ms |
6580 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
10204 KB |
Output is correct |
2 |
Correct |
136 ms |
11580 KB |
Output is correct |
3 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
3548 KB |
Output is correct |
2 |
Correct |
172 ms |
13428 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
22776 KB |
Output is correct |
2 |
Correct |
114 ms |
10176 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2748 KB |
Output is correct |
2 |
Correct |
11 ms |
1584 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
3772 KB |
Output is correct |
2 |
Correct |
74 ms |
5152 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
538 ms |
35224 KB |
Output is correct |
2 |
Correct |
44 ms |
5092 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |