Submission #445716

#TimeUsernameProblemLanguageResultExecution timeMemory
445716prvocisloPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
492 ms28760 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<set<int> > g(n); set<pair<int, int> > pq; for (int u = 0, d; u < n; u++) { cin >> d; for (int j = 0, v; j < d; j++) cin >> v, g[u].insert(v); pq.insert({d, u}); } int ans = 1; while (!pq.empty()) { int u = pq.begin()->second; pq.erase(pq.begin()); vector<int> c = {u}; for (int v : g[u]) c.push_back(v); vector<int> g2(c.size(), 0); for (int i = 0; i < c.size(); i++) for (int j = 0; j < c.size(); j++) if (g[c[i]].count(c[j])) g2[i] |= (1 << j); for (int i = 1; i < (1 << c.size()); i += 2) // prvy bit musime mat { int cnt = __builtin_popcount(i); if (cnt <= ans) continue; bool ok = true; for (int u = 1; u < c.size(); u++) { if (!(i & (1<<u))) continue; for (int v = u+1; v < c.size(); v++) { if (!(i & (1<<v))) continue; if (!(g2[u] & (1<<v))) { ok = false; break; } } if (!ok) break; } if (ok) ans = max(ans, cnt); } for (int v : g[u]) { pq.erase({g[v].size(), v}); g[v].erase(u); pq.insert({g[v].size(), v}); } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = 0; i < c.size(); i++) for (int j = 0; j < c.size(); j++)
      |                         ~~^~~~~~~~~~
politicaldevelopment.cpp:26:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = 0; i < c.size(); i++) for (int j = 0; j < c.size(); j++)
      |                                                            ~~^~~~~~~~~~
politicaldevelopment.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int u = 1; u < c.size(); u++)
      |                             ~~^~~~~~~~~~
politicaldevelopment.cpp:36:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 for (int v = u+1; v < c.size(); v++)
      |                                   ~~^~~~~~~~~~
#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...