Submission #785767

#TimeUsernameProblemLanguageResultExecution timeMemory
785767SlavicGPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
266 ms48680 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() const int N = 5e4 + 10; unordered_set<int> st[N]; vector<int> adj[N]; set<int> aaa[N]; int ans = 1; void solve() { int n, k; cin >> n >> k; queue<int> q; vector<bool> pushed(n, false); for(int i = 0; i < n; ++i) { int x; cin >> x; if(x >= 1) { for(int j = 0; j < x; ++j) { int bl; cin >> bl; aaa[i].insert(bl); st[i].insert(bl); } } if(x < k) { q.push(i); pushed[i] = true; } } while(!q.empty()) { int i = q.front(); q.pop(); for(auto x: aaa[i]) adj[i].pb(x); vector<int> dp(1 << (sz(adj[i])), 0); dp[0] = 1; for(int mask = 0; mask < (1 << (sz(adj[i]))); ++mask) { if(!dp[mask]) continue; int cnt = 1; for(int f = 0; f < sz(adj[i]); ++f) { if(mask >> f & 1) ++cnt; } ans = max(ans, cnt); for(int j = 0; j < sz(adj[i]); ++j) { if(mask >> j & 1) continue; bool check = true; for(int f = 0; f < sz(adj[i]); ++f) { if(mask >> f & 1) { if(st[adj[i][j]].find(adj[i][f]) == st[adj[i][j]].end()) check = false; } } if(check) dp[mask | (1 << j)] = 1; } } for(auto f: adj[i]) { aaa[f].erase(i); if(sz(aaa[f]) < k && !pushed[f]) { pushed[f] = true; q.push(f); } } } cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } }
#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...