并查集
#include <iostream>
#include <algorithm>
using namespace std;
const int N =1e5+7;
int root[N];
int n, m;
int find(int x){
if(root[x] == x) return x;
return root[x] = find(root[x]);
}
int main(){
cin>>n>>m;
for(int i = 0; i <= n; i++){
root[i] = i;
}
char c;
int u, v;
while(m--){
getchar();
cin>>c>>u>>v;
int a = find(u), b = find(v);
if(c == 'M'){
if(a != b) root[b] = a;
}else{
if(a == b) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}