#include <bits/stdc++.h>
using namespace std;
int in() {
  int n;
  scanf("%d", &n);
  return n;
}
long long Lin() {
  long long n;
  scanf("%lld", &n);
  return n;
}
double Din() {
  double n;
  scanf("%lf", &n);
  return n;
}
const long long inf = (long long)1e17;
const long long mod = (long long)1e9 + 7;
const int N = 1e5 + 5;
vector<pair<int, int> > g[N];
bool vis[N];
int par[18][N], mx[18][N], dep[N];
int root[N];
void init(int n) {
  for (int i = 1; i <= n; i++) {
    root[i] = i;
  }
}
int Find(int u) { return root[u] == u ? u : root[u] = Find(root[u]); }
void Union(int u, int v) {
  if (Find(u) != Find(v)) root[Find(u)] = Find(v);
}
void lca_build(int u, int d = 0) {
  vis[u] = true, dep[u] = d;
  for (int i = 1; i <= 17; i++) {
    par[i][u] = par[i - 1][par[i - 1][u]];
    mx[i][u] = max(mx[i - 1][u], mx[i - 1][par[i - 1][u]]);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first, w = g[u][i].second;
    if (!vis[v]) {
      par[0][v] = u;
      mx[0][v] = w;
      lca_build(v, dep[u] + 1);
    }
  }
}
bool lca_query(int u, int v, int val) {
  if (dep[u] < dep[v]) return false;
  for (int i = 17; i >= 0 && u != v; i--) {
    if (dep[par[i][u]] >= dep[v] && mx[i][u] <= val) u = par[i][u];
  }
  if (u == v) return true;
  return false;
}
vector<pair<int, int> > qry;
pair<int, int> pack[N];
int solve() {
  int n = in(), q = in(), cnt = 0;
  init(n);
  for (int i = 1; i <= q; i++) {
    int ck = in();
    if (ck == 1) {
      int u = in(), v = in();
      g[u].push_back({v, i});
      g[v].push_back({u, i});
      Union(u, v);
    } else if (ck == 2) {
      cnt++;
      int x = in();
      pack[cnt] = {x, i};
    } else {
      int x = in(), id = in();
      qry.push_back({x, id});
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Find(i) == i) {
      par[0][i] = i;
      lca_build(i);
    }
  }
  for (auto xx : qry) {
    int u = xx.first, id = xx.second;
    if (lca_query(pack[id].first, u, pack[id].second))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    solve();
  }
  return 0;
}
