MLE?!!!30求条!!
查看原帖
MLE?!!!30求条!!
906970
Jerry_Money楼主2024/8/5 13:47
#include<bits/stdc++.h>
using namespace std;
int n,Q,s;
int opt,x,y;
int f[200086];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int main(){
	cin>>n>>Q;
	for(int i=1;i<=3*n;i++)f[i]=i;
	while(Q--){
		cin>>opt>>x>>y;
		if(x>n||y>n){
			s++;
			continue;
		}
		if(opt-1){
			x=find(x),y=find(y);
			if(x==y){
				s++;
				//cout<<"---"<<opt<<" "<<x<<" "<<y<<endl;
			}
			else {
				f[y]=x+n;	//y是x食物 
				f[x]=y+n+n;	//x是y天敌 
			}
		}
		else {
			x=find(x),y=find(y);
			if(x==y+n||x==y+n+n){
				s++;	
				//cout<<"---"<<opt<<" "<<x<<" "<<y<<endl;
			}
			else f[y]=x;
			
		}
	}
	cout<<s;
}
2024/8/5 13:47
加载中...