#include <bits/stdc++.h>
using namespace std;
#define YES "DA"
#define NO "NE"
vector<vector<int>> layers;
unordered_map<int, bitset<400>> coverage;
bitset<400>& 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<400> 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<400>> leg, cur, prev = {bitset<400>()};
bool g = false;
for(int i = 1; i <= k; i++){
for(int v : layers[i]){
if(coverage[v] == 0)
continue;
for(bitset<400> bs : prev){
if((coverage[v] & bs) == 0 && leg.find(coverage[v] | bs) == leg.end()){
bitset<400> tmp = coverage[v] | bs;
cur.insert(tmp);
leg.insert(tmp);
if(tmp.count() == layers[k].size())
g = true;
}
}
}
swap(cur, prev);
cur.clear();
}
cout << (g ? YES : NO) << "\n";
}
}
Compilation message
burza.cpp: In function 'std::bitset<400>& 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)
| ~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
5208 KB |
Output is correct |
2 |
Correct |
304 ms |
14276 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
1092 ms |
151884 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
352 ms |
14300 KB |
Output is correct |
2 |
Correct |
391 ms |
14280 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
307 ms |
14272 KB |
Output is correct |
6 |
Execution timed out |
1083 ms |
153440 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
350 ms |
14376 KB |
Output is correct |
2 |
Correct |
345 ms |
14284 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
1100 ms |
146368 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
4160 KB |
Output is correct |
2 |
Correct |
326 ms |
14276 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
222 ms |
33788 KB |
Output is correct |
6 |
Correct |
3 ms |
1048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
14192 KB |
Output is correct |
2 |
Correct |
336 ms |
14344 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
1098 ms |
156172 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
14280 KB |
Output is correct |
2 |
Correct |
339 ms |
14272 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
35 ms |
8948 KB |
Output is correct |
6 |
Correct |
512 ms |
67748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
14288 KB |
Output is correct |
2 |
Correct |
355 ms |
14240 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
315 ms |
14232 KB |
Output is correct |
6 |
Execution timed out |
1092 ms |
157788 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
4536 KB |
Output is correct |
2 |
Correct |
365 ms |
14284 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
316 ms |
45456 KB |
Output is correct |
6 |
Execution timed out |
1098 ms |
152020 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2132 KB |
Output is correct |
2 |
Correct |
324 ms |
14188 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
1092 ms |
158352 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
7356 KB |
Output is correct |
2 |
Correct |
398 ms |
14280 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
94 ms |
7316 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |