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<bitset>
#include<iostream>
#include<set>
#include<vector>
using namespace std;
const int N = 3e5 + 123;
set<int>g[N];
vector<int>vec;
int s[N];
vector<int>can;
int em[N];
#define cerr if(false) cerr
int was[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0 ; i < n ; ++ i) {
cin >> s[i];
for (int j = 0 ; j < s[i] ; ++ j) {
int x;
cin >> x;
g[i].insert(x);
}
if (s[i] <= k) {
was[i] = 1;
can.emplace_back(i);
}
}
int ans = 0;
for (int i : can) {
vec = {i};
for (auto it : g[i]) vec.emplace_back(it);
cerr << i << " | ";
for (int v : vec) cerr << v << " ";
cerr << endl;
int m = vec.size();
for (int x = 0 ; x < m ; ++ x) em[x] = 0;
for (int x = 0 ; x < m ; ++ x) {
em[x] |= 1 << x;
for (int y = 0 ; y < m ; ++ y) {
if (g[vec[x]].count(vec[y])) em[x] |= 1 << y;
}
}
for (int mask = 0 ; mask < 1 << m ; ++ mask) {
bool ok = true;
for (int x = 0 ; x < m ; ++ x) {
if (mask >> x & 1) {
if ((mask & em[x]) != mask) ok = false;
}
}
if (ok) ans = max(ans, __builtin_popcount(mask));
}
for (int v : vec) g[v].erase(i);
for (int v : vec) if ((int)g[v].size() <= k && !was[v]) was[v] = 1, can.emplace_back(v);
g[i].clear();
}
cout << ans;
}
# | 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... |