the tenty day - connected blocks
重铸华农荣光 我辈义不容辞
the tenty day - connected blocks
#include<iostream>
using namespace std;
const int N=100010;
int p[N],siz[N];
int find(int x)
{
if(p[x]!=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;
siz[i]=1;
}
while(m--){
char op[2];
int a,b;
cin>>op;
if(op[0]=='C'){
cin>>a>>b;
if(find(a)!=find(b)) {
siz[find(b)]+=siz[find(a)];//务必先执行,否则find(a)=find(b)
p[find(a)]=find(b);
}
}else {
if(op[1]=='1')
{
cin>>a>>b;
if(find(a)==find(b)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}else{
cin>>a;
cout<<siz[find(a)]<<endl;
}
}
}
return 0;
}