0pts求助
查看原帖
0pts求助
933572
liyixuande楼主2023/8/24 14:05

只有第一个和最后一个是对的

#include<bits/stdc++.h>
using namespace std;
bool v1[200005],v2[200005];
int n,m,t,x,y,p=0;
int main(){
	cin>>t>>n>>m;
	while(t>0){
	    int cnt1=0,cnt2=0;
	    memset(v1,false,sizeof(v1));
	    memset(v2,false,sizeof(v2));
	    p=0;
	    for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(x==1){
			if(v2[y]==true){
				cout<<i<<endl;
				p=1;
				break; 
			} 
	        	if(v1[y]==false){
				cnt1++;
				v1[y]=true;
			}
		}
		if(x==2){
			if(v1[y]==true){
				cout<<i<<endl;
				p=1;
				break;
			}
			if(v2[y]==false){
				v2[y]=true;
				cnt2++;
			}
		}
		if(cnt1==n||cnt2>1){
			cout<<i<<endl;
			p=1;
			break;
		}
		}
		if(p==0){
			cout<<-1<<endl;
		}
		t--;
	}
}
2023/8/24 14:05
加载中...