#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <unordered_set>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


const int BLOCK = 200;

struct UnionFind {
  vector<int> data;
  UnionFind(int size=0) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int n, q;

struct Query{
	int t, u, v;
	Query(int t, int u, int v):t(t), u(u), v(v){}
};


int main(){
//	ios::sync_with_stdio(false);
	cin >> n >> q;
	unordered_set<unsigned int> e;
	while(q){
		vector<unordered_set<int>> g(n);
		unordered_set<unsigned int> erase;
		vector<Query> query;
		REP(i, BLOCK){
			int t;
			unsigned int u, v;
			if(!q) break;
			q --;
			cin >> t >> u >> v;
			if(u > v) swap(u, v);
			query.emplace_back(t, u, v);
			if(t == 2) erase.insert((u << 16) | v);
		}
		UnionFind uf(n);
		FOR(it, e){
			const unsigned int u = *it >> 16;
			const unsigned int v = *it & 0xffff;
			if(erase.find(*it) == erase.end()){
				uf.unionSet(u, v);
			}
		}
		FOR(it, e){
			const unsigned int u = *it >> 16;
			const unsigned int v = *it & 0xffff;
			if(erase.find(*it) != erase.end()){
				g[uf.root(u)].insert(uf.root(v));
				g[uf.root(v)].insert(uf.root(u));
			}
		}
		REP(i, query.size()){
			const unsigned int t = query[i].t;
			const unsigned int u = uf.root(query[i].u);
			const unsigned int v = uf.root(query[i].v);
			if(t == 1){
				g[u].insert(v);
				g[v].insert(u);
				e.insert((query[i].u << 16) | query[i].v);
			}else if(t == 2){
				g[u].erase(v);
				g[v].erase(u);
				e.erase((query[i].u << 16) | query[i].v);
			}else if(t == 3){
				queue<int> que;
				que.push(uf.root(u));
				unordered_set<int> visited;
				visited.insert(u);
				int ans = 0;
				while(!que.empty()){
					int u = que.front(); que.pop();
					if(u == v){
						ans = 1;
						break;
					}
					FOR(v, g[u])if(visited.find(*v) == visited.end()){
						visited.insert(*v);
						que.push(*v);
					}
				}
				cout << (ans ? "YES":"NO") << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 8676