Submission #997466

# Submission time Handle Problem Language Result Execution time Memory
997466 2024-06-12T11:09:52 Z amirhoseinfar1385 Political Development (BOI17_politicaldevelopment) C++17
4 / 100
2 ms 860 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10;
vector<int>adj[maxn];
int cnt[maxn],n,k,tartib[maxn],mask[maxn],msk[maxn],ind[maxn],lg[maxn];

void vorod(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>cnt[i];
		adj[i].resize(cnt[i]);
		for(int j=0;j<cnt[i];j++){
			cin>>adj[i][j];
		}
	}
}

bool cmp(int a,int b){
	return tartib[b]<tartib[a];
}

void pre(){
	lg[1]=0;
	for(int i=2;i<(1<<10);i++){
		lg[i]=lg[i/2]+1;
	}
	vector<int>v;
	for(int i=0;i<n;i++){
		if(cnt[i]<k){
			v.push_back(i);
		}
	}
	for(int i=0;i<n;i++){
		//cout<<v.size()<<" "<<v[i]<<endl;
		tartib[v[i]]=i;
		for(auto x:adj[v[i]]){
			//cout<<"kam: "<<x<<" "<<i<<" "<<cnt[x]<<endl;
			cnt[x]--;
			if(cnt[x]==k-1){
				v.push_back(x);
			}
		}
	}
	for(int i=0;i<n;i++){
		sort(adj[i].begin(),adj[i].end(),cmp);
		while((int)adj[i].size()>0&&tartib[adj[i].back()]<tartib[i]){
			adj[i].pop_back();
		}
	}
}

int cal(int u){
	//cout<<u<<" "<<(int)adj[u].size()<<" hey"<<endl;
	for(int i=0;i<(int)adj[u].size();i++){
		ind[adj[u][i]]=i;
	}
	for(int i=0;i<(int)adj[u].size();i++){
		int v=adj[u][i];
		msk[v]|=(1<<ind[v]);
		for(auto x:adj[v]){
			if(ind[x]==-1){
				continue;
			}
			msk[v]|=(1<<ind[x]);
		}
	}
	mask[0]=(1<<k)-1;
	int ret=0;
	for(int i=1;i<(1<<(int)adj[u].size());i++){
		int w=(i&(-i));
		int v=adj[u][lg[w]];
		mask[i]=(mask[i^w]&msk[v]);
		if((mask[i]&i)==i){
			ret=max(ret,__builtin_popcount(i));
		}
	}	
	ret++;
	return ret;
}

void solve(){
	//cout<<"salam"<<endl;
	int res=1;
	for(int i=0;i<maxn;i++){
		ind[i]=-1;
	}
	for(int i=0;i<n;i++){
		res=max(res,cal(i));
	}
	cout<<res<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	vorod();
	pre();
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 808 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 808 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Incorrect 0 ms 604 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Incorrect 1 ms 600 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 808 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Incorrect 0 ms 604 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 808 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Incorrect 0 ms 604 KB Output isn't correct
16 Halted 0 ms 0 KB -