#include<bits/stdc++.h>
using namespace std;
int n,m,fa[300010],ran[300010];
struct Node{
int xx,fat;
};
stack<Node> last;
int fin(int q){
return (q==fa[q])?q:fin(fa[q]);
}
void unite(int x,int y){
if(x==y){
last.push({-1,-1});
return;
}
if(ran[x]<ran[y]){
last.push({x,fa[x]});
fa[x]=y;
}
else{
last.push({y,fa[y]});
fa[y]=x;
if(ran[x]==ran[y]) ran[x]++;
}
}
void del(){
Node d=last.top();
last.pop();
if(d.xx==-1) return;
fa[d.xx]=d.fat;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=m;i++){
int op,x,y;
cin>>op;
if(op==1){
cin>>x>>y;
unite(fin(x),fin(y));
}
else if(op==2&&!last.empty()){
del();
}
else{
cin>>x>>y;
if(fin(x)==fin(y))cout<<"Yes";
else cout<<"No";
cout<<'\n';
}
}
return 0;
}