60分wa求助
查看原帖
60分wa求助
941801
louie2011楼主2024/8/7 21:56
#include<bits/stdc++.h>
using namespace std;
int n,g,ans;
int group[250050];
int groups[250050];
bool invited[1000050],invitedgroup[250050];
int main()
{
	invited[1]=1;
	ans=1;
	cin>>n>>g;
	int pos=0;
	for(int i=1;i<=g;i++)
	{
		int k;
		cin>>k;
		groups[i]=k;
		for(int j=1;j<=k;j++)
		{
			pos++;
			int tmp;
			cin>>tmp;
			group[pos]=tmp;
		}
	}
	bool newcow=1;
	while(newcow)
	{
		newcow=0;
		pos=0;
		for(int i=1;i<=g;i++)
		{
			if(invitedgroup[i])
			{
				pos+=groups[i];
				continue;
			}
			int cnt=0,notpos=-1;
//			cout<<"group "<<i<<" ,from "<<pos+1<<" to "<<pos+groups[i]<<endl;
			for(int j=pos+1;j<=pos+groups[i];j++)
			{
				if(invited[group[j]])
				{
					cnt++;
				}
				else
				{
					notpos=j;
				}
			}
//			cout<<"invited="<<cnt<<endl;
			if(cnt==groups[i]-1)
			{
				invited[group[notpos]]=1;
				invitedgroup[i]=1;
				pos+=groups[i];
				newcow=1;
				ans++;
//				cout<<"invite group "<<i<<" and invite cow "<<group[notpos]<<endl;
				continue;
			}
			else if(cnt<groups[i]-1)
			{
				pos+=groups[i];
				continue;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

https://www.luogu.com.cn/record/171263996

2024/8/7 21:56
加载中...