osky123456 @ 2022-01-14 20:58:06
不知道怎么优化了,求助
#include<bits/stdc++.h>
#define MAXN 10001
using namespace std;
int n,m,fa[MAXN];
int find(int x){
return x==fa[x]?x:find(fa[x]);
}
int main(){
int x,y;
cin>>n>>m;
for(int i=1;i<=n;i++) fa[i]=i;
while(m--){
int data;
cin>>data>>x>>y;
if(data==2){
if(find(x)==find(y))
cout<<"Y"<<endl;
else cout<<"N"<<endl;
}
else{
fa[find(x)]=find(y);
}
}
return 0;
}
by 0htoAi @ 2022-01-14 21:53:28
@joy2010WonderMaker 确实