#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(), v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define INF (ll)1e9
#define oo (ll)1e18
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
void print(vector<pair<int, int>> v){
for(auto x: v) cout << x.first << ' ' << x.second << '\n';
}
struct seg{
vector<pair<int, int>> mi;
int n;
seg(int _n = 0){
n = _n;
mi.resize(4 * n, {0, 0});
}
void update(int p, int c){
int i = 1, l = 0, r = n - 1;
while(l < r){
int m = (l + r) >> 1;
if(p <= m){
r = m;
i = i * 2;
}
else{
l = m + 1;
i = i * 2 + 1;
}
}
mi[i].first += c;
mi[i].second = p;
while(i > 1){
i >>= 1;
mi[i] = min(mi[i * 2], mi[i * 2 + 1]);
}
}
};
ll solve(){
int n, k; cin >> n >> k;
vector<vector<int>> adj(n);
for(int i = 0; i < n; i++){
int k; cin >> k;
while(k--){
int x; cin >> x;
adj[i].push_back(x);
}
sort(adj[i].begin(), adj[i].end());
}
auto Find = [&](vector<int> &v, int c){
int p = lower_bound(v.begin(), v.end(), c) - v.begin();
if(p == (int)v.size() || v[p] != c) return false;
return true;
};
auto check = [&](vector<int> &V){
for(int i = 0; i < (int)V.size(); i++){
int u = V[i];
for(int j = i + 1; j < (int)V.size(); j++){
int v = V[j];
if(!Find(adj[u], v)) return false;
}
}
return true;
};
seg it(n);
for(int i = 0; i < n; i++){
it.update(i, (int)adj[i].size());
}
vector<int> del(n);
int ans = 1;
for(int t = 0; t < n; t++){
int u = it.mi[1].second;
vector<int> V;
for(int v: adj[u]){
if(!del[v]) V.push_back(v);
}
for(int mask = 0; mask < MASK((int)V.size()); mask++){
vector<int> V1;
for(int i = 0; i < (int)V.size(); i++){
if(BIT(mask, i)) V1.push_back(V[i]);
}
if(check(V1)) maximize(ans, __builtin_popcount(mask) + 1);
}
del[u] = true;
it.update(u, INF);
for(int v: adj[u]){
it.update(v, -1);
}
}
return ans;
return 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
cout << solve() << '\n';
}
return 0;
}
# | 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... |