#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 40005;

map<P,int> mp;

class UF_pop {
public:
	vector<int> par,nrank; vector<vector<int> > hist;
    int sz;
	UF_pop(int node_size){
        sz = node_size;
        par = nrank = vector<int>(sz,0);
        rep(i,sz){
            par[i] = i;
        }
    }
	void reinit(){
        rep(i,sz){
            nrank[i] = 0; par[i] = i;
        }
    }
	int find(int x){
        return (par[x] == x)?(x):find(par[x]);
    }
	void pop(){
		if(len(hist)) {
			auto a = hist.back();
			hist.pop_back();
			par[a[0]] = a[1]; nrank[a[0]] = a[2];
			par[a[3]] = a[4]; nrank[a[3]] = a[5];
		}
	}
	void unite(int x,int y) {
		x = find(x); y = find(y);
		hist.pb({x,par[x],nrank[x],y,par[y],nrank[y]});
		if(x == y) return;
		if(nrank[x] < nrank[y]){
            par[x] = y;
        }else{
            nrank[x] += (nrank[x] == nrank[y]);
			par[y] = x;
        }
	}
    bool same(int x,int y){
        return find(x) == find(y);
    }
};
void dfs(int l, int r, UF_pop& uf, vvi vvec, vi& id, vvi& que,vi& res) {
	vvi lvec,rvec,lque,rque;
	int nums=0;
	int mid = (l+r) / 2;
	int con=0;
    int st = lower_bound(all(id),l) - id.begin();
    int ed = lower_bound(all(id),r) - id.begin();
    if(ed <= st){
        return;
    }
	if(vvec.empty()){
        srep(i,st,ed){
            if(uf.same(que[i][0],que[i][1])){
                res[i] = 1;
            }
        }
        return;
    }
	each(v,vvec){
		if(v[2] <= l && r <= v[3]) {
			uf.unite(v[0],v[1]);
			nums++;
		}else{
			if(v[2] < mid){
                lvec.pb({v[0],v[1],max(l,v[2]),min(mid,v[3])});
            }
			if(v[3] > mid){
                rvec.pb({v[0],v[1],max(mid,v[2]),min(r,v[3])});
            }
		}
	}
	dfs(l,mid,uf,lvec,id,que,res);
	dfs(mid,r,uf,rvec,id,que,res);
	while(nums){
        uf.pop();
        --nums;
    }
}

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    vi id;
    vvi vec, que;
	rep(i,q){
		int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        if(x == 1){
            mp[{y,z}] = i;
        }else if(x == 2){
            vec.pb({y,z,mp[{y,z}],i});
            mp.erase({y,z});
        }else{
            id.pb(i);
            que.pb({y,z});
        }
	}
	each(it,mp){
        vec.pb({(it.fi).fi,(it.fi).se,it.se,q});
    }
	UF_pop uf(n);
    vi res(len(que),0);
	dfs(0,q,uf,vec,id,que,res);
    rep(i,len(res)){
        if(res[i]){
            cout << "YES\n";
        }else{
            cout << "NO\n";
        }
    }
    return 0;
}

Measured memory_bytes: 14444