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>
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<ll, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
// #ifndef ONLINE_JUDGE
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
// #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e4 + 5, maxk = 11, lg = 35, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
vector<int> adj[maxn];
vector<int> mask[maxk][maxk];
int cnt[maxn];
bool chk(int x, vector<int> cand){
int n = sz(cand);
vector<int> adj(n);
rep(i,0,n) {
adj[i] ^= 1<<i;
rep(j,0,i){
auto it = lower_bound(all(::adj[cand[i]]), cand[j]);
if(it != end(::adj[i]) && *it == cand[j]) adj[i] ^= 1<<j, adj[j] ^= 1<<i;
}
}
for(int m: mask[n][x]){
bool ok = true;
rep(i,0,n) if((m>>i&1) && (adj[i]&m) != m) {
ok = false;
break;
}
if(ok) return true;
}
return false;
}
int main(){ IOS();
int n, k, ans = 1; cin >> n >> k;
set<pp> s;
rep(i,0,n){
int d; cin >> d;
s.insert({cnt[i] = d, i});
adj[i].resize(d);
rep(j,0,d) cin >> adj[i][j];
sort(all(adj[i]));
}
rep(i,0,k+1){
rep(j,0,1<<i) mask[i][__builtin_popcount(j)].pb(j);
}
while(sz(s)){
int r = s.begin()->ss;
s.erase(begin(s)), cnt[r] = -1;
vector<int> ad{r};
for(int c: adj[r]) if(cnt[c] > 0){
ad.pb(c);
s.erase(pp(cnt[c], c));
s.insert({--cnt[c], c});
}
// er(r);
// for(int c: ad) cerr << c << ' '; cerr << endl;
while(ans < sz(ad) && chk(ans+1, ad)) ans++;
}
cout << ans << '\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... |