Submission #674552

#TimeUsernameProblemLanguageResultExecution timeMemory
674552Nicolas125841Burza (COCI16_burza)C++14
0 / 160
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define YES "DA" #define NO "NE" vector<vector<int>> layers; vector<bitset<20>> coverage; bitset<20> 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<20> 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>()); coverage = vector<bitset<20>>(n, bitset<20>()); 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<20>> cur, prev = {bitset<20>()}; bool g = false; for(int i = 1; i <= k; i++){ for(int v : layers[i]){ for(bitset<20> 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 (stderr)

burza.cpp: In function 'std::bitset<20> 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:55:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |     if(layers.size() <= k)
      |        ~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...