连通块问题,balabalabala
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int n,m;
int p[N],cnt[N];
int find(int x){
if(p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;++i){
p[i] = i;
cnt[i] = 1;
}
while(m--){
string op;
int a,b;
cin >> op;
if(op == "C"){
scanf("%d%d",&a,&b);
a = find(a),b = find(b);
if(a != b){
p[a] = b;
cnt[b] += cnt[a];
}
}else if(op == "Q1"){
scanf("%d%d",&a,&b);
if(find(a) == find(b)) puts("Yes");
else puts("No");
}else{
scanf("%d",&a);
printf("%d\n",cnt[find(a)]);
}
}
return 0;
}