#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[0]; nrank[a[0]] = a[1];
			par[a[2]] = a[2]; nrank[a[2]] = a[3];
		}
	}
	void unite(int x,int y) {
		x = find(x); y = find(y);
		hist.pb({x,nrank[x],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, vi& vid, vi& qid, const vvi& vec, const vvi& que, vi& res) {
	vi lvid,rvid;
	int num=0;
	int mid = (l+r) / 2;
    int st = lower_bound(all(qid),l) - qid.begin();
    int ed = lower_bound(all(qid),r) - qid.begin();
    if(ed <= st){
        return;
    }
	if(vid.empty()){
        srep(i,st,ed){
            if(uf.same(que[i][0],que[i][1])){
                res[i] = 1;
            }
        }
        return;
    }
	each(i,vid){
		const vi& v = vec[i];
		if(v[2] <= l && r <= v[3]) {
			uf.unite(v[0],v[1]);
			++num;
		}else{
			if(v[2] < mid){
                lvid.pb(i);
            }
			if(v[3] > mid){
                rvid.pb(i);
            }
		}
	}
	dfs(l,mid,uf,lvid,qid,vec,que,res);
	dfs(mid,r,uf,rvid,qid,vec,que,res);
	while(num){
        uf.pop();
        --num;
    }
}

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    vi vid,qid;
    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{
            qid.pb(i);
            que.pb({y,z});
        }
	}
	each(it,mp){
        vec.pb({(it.fi).fi,(it.fi).se,it.se,q});
    }
	vid.resize(len(vec));
	iota(all(vid),0);
	UF_pop uf(n);
    vi res(len(que),0);
	dfs(0,q,uf,vid,qid,vec,que,res);
    rep(i,len(res)){
        if(res[i]){
            cout << "YES\n";
        }else{
            cout << "NO\n";
        }
    }
    return 0;
}

Measured memory_bytes: 7608