22017gdgzoi48 @ 2019-05-24 20:41:11
#include<iostream>
using namespace std;
#define N 20001
int n,m,fa[N],x,y,op;
int findFa(int v){return fa[v]==v?v:fa[v]=findFa(fa[v]);}
void unionn(int v,int u){fa[v]=u;}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1;i<=m;i++){
cin>>op>>x>>y;
int fx=findFa(x),fy=findFa(y);
if(op==1){if(fx!=fy){unionn(x,y);}}
else {
if(fx==fy)cout<<"Y\n";
else cout<<"N\n";
}
}
}
help
by 2017gdgzoi999 @ 2019-05-24 20:43:47
这位是221世纪的大佬
by 22017gdgzoi48 @ 2019-05-24 20:44:53
别说话
by 2017gdgzoi999 @ 2019-05-24 20:49:34
if(op==1){if(fx!=fy){unionn(x,y);}}
这里错了
应为
if(op==1){if(fx!=fy){unionn(fx,fy);}}