题解不对吧???
查看原帖
题解不对吧???
688891
封禁用户楼主2022/7/31 21:56

蒟蒻的问题

题解里面输入样例:

4 7
2 1 2
1 1 2
2 1 2
1 3 4
2 1 4
1 2 3
2 1 4

输出的是:

N
Y
N
N

然后对了???? 求解

还有
求各位dalao看看本蒟蒻的码哪里错了??
#include<bits/stdc++.h> 
using namespace std;
int a[100100];
int n,m,z,x,y;
int findfather(int x){
	if(x=a[x]){
		return x;
	}
	else{
		return a[x]=findfather(a[x]);
	}
}
int main(){
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		a[i]=i;
	}
	for(int i=1;i<=m;i++){
		cin>>z>>x>>y;
		if(z==1){
			a[findfather(x)]=findfather(y);
		}
		if(z==2){
			if(findfather(x)==findfather(y)){
				cout<<"Y"<<endl;
			}
			else{
				cout<<"N"<<endl;
			}
		}
	}
	return 0;
}
2022/7/31 21:56
加载中...