TLE第2,3组的第一个
查看原帖
TLE第2,3组的第一个
872386
Officer楼主2024/8/16 23:31
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
bool a[200005];
bool check()
{
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=1)
		{
			return 0;
		}
	}
	return 1;
}
signed main()
{
	//freopen("string.in", "r", stdin);
	//freopen("string.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		memset(a,0,sizeof(a));
		bool flag=0,f=0,fx=0;
		cin>>n>>m;
		for(int i=1;i<=m;i++)
		{
			int op,x;
			cin>>op>>x;
			if(flag==1)
			{
				continue;
			}
			if(op==1)
			{
				a[x]=1;
			}
			else
			{
				for(int i=1;i<=n;i++)
				{
					if(i!=x)
					{
						a[i]=1;
					}
				}
			}
			if(check())
			{
				cout<<i<<endl;
				flag=1;
			}
		}
		if(flag==0)
		{
			cout<<-1<<endl;
		}
	}
	return 0;
}
/*
*/

2024/8/16 23:31
加载中...