笔记
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e5 +10;
int z,x,y;
int n,m;
int pre[inf];
int root(int x){
if(x == pre[x]) return x;
else {
pre[x] = root(pre[x]);
return pre[x];
}
}
void Merge(int x,int y){
pre[root(x)] = root(y);
}
bool isCon(int x,int y){
return root(x) == root(y);
}
int main(){
cin >> n >> m;
for(int i = 0;i < n;i++) pre[i] = i;
while(m--){
cin >> z >> x >> y;
if(z == 1) Merge(x,y);
else if(z == 2) {
if(isCon(x,y)) cout <<"Y" << endl;
else cout <<"N"<<endl;
}
}
return 0;
}