#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int const N = 2e5 + 123;
int p[N], n, q, sz[N], w[N], st;
void init() {
  for (int i = 1; i <= n; ++i) {
    sz[i] = 0;
    p[i] = i;
    w[i] = i + 1;
  }
}
int find(int v) {
  if (p[v] == v) {
    return v;
  }
  return p[v] = find(p[v]);
}
void unit(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) {
    return;
  }
  if (sz[a] < sz[b]) {
    swap(a, b);
  }
  p[b] = a;
  if (sz[a] == sz[b]) {
    ++sz[a];
  }
}
int proc(int x, int y) {
  if (x > y) {
    return x;
  }
  w[x] = proc(w[x], y);
  unit(x, st);
  return w[x];
}
int main() {
  scanf("%d%d", &n, &q);
  init();
  for (int i = 0; i < q; ++i) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    if (t == 1) {
      unit(x, y);
    } else {
      if (t == 2) {
        st = x;
        if (x >= y) {
          continue;
        }
        proc(x, y);
      } else {
        x = find(x);
        y = find(y);
        if (x == y) {
          printf("YES\n");
        } else {
          printf("NO\n");
        }
      }
    }
  }
  return 0;
}
