作者:
_如鲸向海
,
2022-06-14 20:59:15
,
所有人可见
,
阅读 8
#include <iostream>
#include <string>
using namespace std;
const int N = 100010;
int p[N],Size[N];
int find(int x){
if(x!=p[x]) p[x] = find(p[x]);
return p[x];
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) {
p[i] = i;
Size[i] = 1;
}
while(m--){
string op;
int a,b;
cin>>op;
if(op=="C"){
scanf("%d%d",&a,&b);
if(find(a)!=find(b)){
Size[find(a)] += Size[find(b)];
p[find(b)] = find(a);
}
}
else if(op=="Q1"){
scanf("%d%d",&a,&b);
if(find(a)!=find(b))
puts("No");
else
puts("Yes");
}
else if(op=="Q2"){
scanf("%d",&a);
cout<<Size[find(a)]<<endl;
}
}
return 0;
}