```#include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N =100100;
int n,m;
int p[N],r[N];
int find(int a)
{
if(p[a]!=a)p[a]=find(p[a]);
return p[a];
}
void merge(int a,int b)
{
a=find(a),b=find(b);
if(a==b) return;
if(r[a]>r[b]) p[b]=a;
else
{
p[a]=b;
if(r[a]==r[b]) r[b];
}
}
int main()
{
scanf(“%d%d”,&n,&m);
//每个点都是一个集合
for(int i=1;i<=n;i)
{
p[i]=i;
r[i]=1;
}
//操作次数
while(m–)
{
char op[2];
//两个集合
int a,b;
scanf(“%s%d%d”,op,&a,&b);
if(*op==’Q’)
{
if(find(a)==find(b))puts(“Yes”);
else puts(“No”);
}else merge(a,b);
}
return 0;
}
```