题目链接:题目点这里

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const   int N=100010;
int p[N];
int find(int x)
{
   
    if(x!=p[x])
    {
   
        p[x]=find(p[x]);
    }
    return p[x];
}
int n,m;
int main()
{
   
    
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    p[i]=i;
    while(m--)
    {
   
        int a,b;
        char op[2];
        cin>>op;
        if(op[0]=='Q')
        {
   
            cin>>a>>b;
            if(find(a)==find(b))
            cout<<"Yes"<<endl;
            else
            cout<<"No"<<endl;
        }
        else
        {
   
            cin>>a>>b;
            p[find(a)]=find(b);
        }
    }
    return 0;
}