# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785571 | SlavicG | Political Development (BOI17_politicaldevelopment) | C++17 | 573 ms | 26268 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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()
void solve() {
int n, k; cin >> n >> k;
unordered_set<int> st[n + 1];
vector<vector<int>> adj(n);
for(int i = 0; i < n; ++i) {
int x; cin >> x;
if(x >= 1) {
adj[i].resize(x);
for(int j = 0; j < x; ++j) {
cin >> adj[i][j];
st[i].insert(adj[i][j]);
st[adj[i][j]].insert(i);
}
}
}
int ans = 1;
for(int i = 0; i < n; ++i) {
if(sz(adj[i]) >= k) continue;
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;
ans = max(ans, __builtin_popcount(mask) + 1);
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;
}
}
}
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();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |