雨辰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 Walker_V @ 2019-10-01 11:54:04
论如何边看阅兵边水洛谷
by Clear_02 @ 2019-10-01 11:54:05
还愣着干嘛,快膜拜啊%%%
by tiger0133 @ 2019-10-01 11:54:13
连初始化都不用,多好 qwq
by Walker_V @ 2019-10-01 11:54:45
还膜拜干嘛,快愣着啊%%%
by Walker_V @ 2019-10-01 11:55:04
@⚡cdecl⚡ 对这个甚至不用初始化
by tiger0133 @ 2019-10-01 11:56:54
@YUSS洛水天依 我发现我对很多数据结构/算法的惯用实现方式并不是很常见诶
by tiger0133 @ 2019-10-01 11:57:09
虽然这样明显更方便
by Walker_V @ 2019-10-01 11:57:40
@⚡cdecl⚡ 那是因为您太强了,都不用惯用的实现方式
by tiger0133 @ 2019-10-01 11:58:08
每日被 D (3/1000)
by Walker_V @ 2019-10-01 11:59:33
@⚡cdecl⚡ 不不不,这是膜拜%%%