救救救救救救救
查看原帖
救救救救救救救
401967
baigu楼主2023/5/16 13:18
#include<bits/stdc++.h>
using namespace std;
int t;
int n,m;
bool a1[200005],a2[200005];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		memset(a1,false,sizeof(a1));
		memset(a2,false,sizeof(a2));
		scanf("%d%d",&n,&m);
		int s1=0,s2=0;
		bool bj=false;
		for(int i=1;i<=m;++i)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			if(x==1)
			{
				if(!a1[y])++s1,a1[y]=true;
				if(s1==n&&!bj)bj=true,printf("%d\n",i);
			}
			else
			{
				if(!a2[y])++s2,a2[y]=true;
				if(a1[y]&&a2[y]&&!bj)bj=true,printf("%d\n",i);
				if(s2==2&&!bj)bj=true,printf("%d\n",i);
			}
		}
		if(!bj) printf("-1\n");
	}
	return 0;
}

错误情况

2023/5/16 13:18
加载中...