#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10, inf = 1e18, mod = 1e9 + 7;
struct DSU {
  long long par[maxn], nx[maxn], N, ted = 0;
  DSU() {
    for (int i = 0; i < maxn; i++) {
      par[i] = i;
      nx[i] = i + 1;
    }
  }
  long long gpar(long long v) {
    if (par[v] == v) {
      return v;
    }
    return par[v] = gpar(par[v]);
  }
  void mrg(long long v, long long u) {
    v = gpar(v);
    u = gpar(u);
    if (v == u) {
      return;
    }
    par[v] = u;
    ted--;
  }
  long long mrgb(long long v, long long u) {
    if (nx[v] > u) {
      return nx[v];
    }
    mrg(v, nx[v]);
    return nx[v] = mrgb(nx[v], u);
  }
  bool smlf(long long v, long long u) { return (gpar(v) == gpar(u)); }
  long long tmlf() { return N + ted; }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  DSU G;
  long long n, q, t, x, y;
  cin >> n >> q;
  while (q--) {
    cin >> t >> x >> y;
    if (t == 1) {
      G.mrg(x, y);
    } else if (t == 2) {
      G.mrgb(x, y);
    } else {
      cout << (G.smlf(x, y) ? "YES" : "NO") << endl;
    }
  }
  return 0;
}
