#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 4000005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)
int n, t, k, m[N], b[N], answer;
set <int> vip[N];
vector <int> v;
void find(int x,int cnt) {
if(cnt > k) return;
if(x == n + 1) {
t = sz(v);
answer = max(answer,t);
return;
}
bool tr = 0;
for(auto i : v) {
if(vip[i].find(x) == vip[i].end()) {
tr = 1;
break;
}
}
if(!tr) {
v.pb(x);
b[x] = 1;
find(x + 1, cnt + 1);
v.pop_back();
}
b[x] = 0;
find(x + 1, cnt);
}
void solve(int x,int sz_v,int cnt,int p) {
if(cnt > k) return;
if(sz_v + 1 == x) {
int cnt = 0, ans = 1;
for(auto i : vip[p]) {
cnt++;
if(!b[cnt])continue;
int cnt2 = 0;
for(auto j : vip[p]) {
cnt2++;
if(!b[cnt2] || cnt == cnt2) continue;
if(vip[i].find(j) == vip[i].end()) return;
}
}
int cnt3 = 0;
for(int i = 1; i <= sz_v; i++) {
if(b[i]) cnt3++;
}
answer = max(answer,cnt3);
return;
}
for(int i = 0; i <= 1; i++) {
b[x] = i;
solve(x+1,sz_v, cnt + i, p);
}
}
int main () {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> m[i];
for(int j = 1; j <= m[i]; j++) {
int x;
cin >> x;
x++;
vip[i].insert(x);
}
}
if(n <= 5000 && k <= 3) {
find(1,0);
cout << answer << '\n';
return 0;
}
for(int i = 1; i <= n; i++) {
solve(1, sz(vip[i]), 0, i);
}
cout << answer + 1 << '\n';
}
# | 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... |