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;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN=5e4+5; //make sure this is right
const int mod=1e9+7;
set<int> graph[mxN];
vector<int> cur;
int n,k;
bool dfs(int s){
if(!s)
return 1;
int at=cur.back();
for(int i:graph[at]){
if(sz(graph[i])<s-1)
continue;
int bad=0;
for(int &j:cur){
if(!graph[j].count(i)){
bad=1;
break;
}
}
if(bad)
continue;
cur.pb(i);
if(dfs(s-1))
return 1;
cur.pop_back();
}
return 0;
}
bool check(int s){
for(int i=0;i<n;i++){
if(sz(graph[i])<s-1)
continue;
cur={i};
if(dfs(s-1))
return 1;
}
return 0;
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n>>k;
int cnt=0;
for(int i=0;i<n;i++){
int d; cin>>d;
if(2*d>=n)
cnt++;
while(d--){
int x; cin>>x;
graph[i].insert(x);
}
}
if(cnt*2>=n){
cout<<k<<"\n";
return 0;
}
for(int i=0;i<n;i++){
vector<int> rem;
for(int j:graph[i]){
if(!graph[j].count(i) || j<=i)
rem.pb(j);
}
for(int &j:rem)
graph[i].erase(j);
}
int l=1; int r=k;
int ans=1;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
ans=mid; l=mid+1;
} else{
r=mid-1;
}
}
cout<<ans<<"\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... |