雨辰yoha @ 2019-10-01 11:46:48
看看我哪里错了呗QAQ
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int MAXX=200005;
int z[MAXX] ,x[MAXX],y[MAXX],fa[MAXX];
int getf(int need){
if(fa[need]=need){
return need;
}
fa[need]==getf(fa[need]);
return fa[need];
}
bool find(int a,int b){
int fa=getf(a);
int fb=getf(b);
if(fa==fb){
return true;
}
return false;
}
void merge(int x,int y){
if(!find(x,y)){
fa[y]=fa[x];
}
return ;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>z[i]>>x[i]>>y[i];
if(z[i]==1){
merge(x[i],y[i]);
}else{
if(find(x[i],y[i])){
cout<<"Y"<<endl;
}else{
cout<<"N"<<endl;
}
}
}
}
输入
4 7
2 1 2
1 1 2
2 1 2
1 3 4
2 1 4
1 2 3
2 1 4
输出
N
N
N
N
by 雨辰yoha @ 2019-10-01 11:51:31
@蒟蒻小猫猫 ?
这是什么毒瘤
by 雨辰yoha @ 2019-10-01 11:51:48
@YUSS洛水天依 啊谢谢QAQ
by Walker_V @ 2019-10-01 11:51:50
@蒟蒻小猫猫 是的
int getf(int x) {
return fa[x]==x?x:fa[x]=getf(fa[x]);
}
by Clear_02 @ 2019-10-01 11:52:20
@YUSS洛水天依 我觉得这样好看qwq
by Walker_V @ 2019-10-01 11:52:20
三目这样打就行了
by Walker_V @ 2019-10-01 11:53:03
@蒟蒻小猫猫 我平时也是这样打的
by tiger0133 @ 2019-10-01 11:53:09
@雨辰yoha 这样多好看 QAQ
int _[N];int f(int x){return _[x]?_[x]=f(_[x]):x;}void $(int x,int y){(x=f(x))^(y=f(y))&&(_[x]=y);}
by Clear_02 @ 2019-10-01 11:53:22
@YUSS洛水天依 qwq
by Walker_V @ 2019-10-01 11:53:32
@⚡cdecl⚡ Orz%%%
by Clear_02 @ 2019-10-01 11:53:41
@⚡cdecl⚡ ·····