#include <bits/stdc++.h>
using namespace std;
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 (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    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;
int n, m;
class LCA {
  int n;
  vector<vector<int>> parent;
  vector<int> depth;
  long long int ans;
  int maxdepth;
  void initdfs(vector<vector<int>> &g, int r, int p, int d) {
    depth[r] = d;
    parent[0][r] = p;
    for (int i = 0; i < (int)(g[r].size()); i++)
      if (g[r][i] != p) initdfs(g, g[r][i], r, d + 1);
  }

 public:
  LCA(vector<vector<int>> &g, int root) {
    n = g.size();
    maxdepth = 0;
    while (n >> maxdepth) maxdepth++;
    parent = vector<vector<int>>(maxdepth + 1, vector<int>(n));
    depth = vector<int>(n);
    parent[0][0] = -1;
    initdfs(g, root, -1, 0);
    for (int k = 0; k < (int)(maxdepth); k++) {
      for (int i = 0; i < (int)(n); i++) {
        if (parent[k][i] < 0)
          parent[k + 1][i] = -1;
        else
          parent[k + 1][i] = parent[k][parent[k][i]];
      }
    }
  }
  long long int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    long long int ans = 0;
    for (int k = 0; k < (int)(maxdepth + 1); k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = ((int)(maxdepth + 1) - 1); k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : 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)]; }
};
struct Query {
  int t, x, y;
  Query(int tt, int xx, int yy) {
    t = tt;
    x = xx;
    y = yy;
  }
};
int main() {
  scanf("%d%d", &n, &m);
  vector<vector<int>> g(n + 1);
  vector<int> par(n, -1);
  vector<vector<pair<int, int>>> ask(m);
  vector<Query> Q;
  for (int i = 0; i < (int)(m); i++) {
    int t, x, y = 0;
    scanf("%d%d", &t, &x);
    x--;
    if (t == 1) {
      scanf("%d", &y);
      y--;
      par[x] = y;
      g[x].push_back(y);
      g[y].push_back(x);
    } else if (t == 2) {
    } else {
      scanf("%d", &y);
      y--;
      ask[y].push_back(pair<int, int>(x, i));
    }
    Q.emplace_back(t, x, y);
  }
  for (int i = 0; i < (int)(n); i++) {
    if (par[i] == -1) {
      g[n].push_back(i);
      g[i].push_back(n);
    }
  }
  LCA lca(g, n);
  UnionFind uf(n);
  int k = 0;
  vector<pair<int, int>> ans;
  for (int i = 0; i < (int)(m); i++) {
    int t = Q[i].t;
    int x = Q[i].x;
    int y = Q[i].y;
    if (t == 1) uf.unionSet(x, y);
    if (t == 2) {
      if (k < ask.size())
        for (__typeof((ask[k]).begin()) to = (ask[k]).begin();
             to != (ask[k]).end(); to++) {
          ans.emplace_back(to->second, (uf.findSet(x, to->first) &&
                                        lca.lca(x, to->first) == to->first));
        }
      k++;
    }
  }
  sort(ans.begin(), ans.end());
  for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); it++)
    puts(it->second ? "YES" : "NO");
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:

  * either employee y became the boss of employee x (at that, employee x didn't have a boss before); 
  * or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive); 
  * or comes a request of type "determine whether employee x signs certain documents". 



Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of employees and the number of events. 

Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3). 

  * If t = 1, then next follow two integers x and y (1 ≤ x, y ≤ n) — numbers of the company employees. It is guaranteed that employee x doesn't have the boss currently. 
  * If t = 2, then next follow integer x (1 ≤ x ≤ n) — the number of the employee who got a document packet. 
  * If t = 3, then next follow two integers x and i (1 ≤ x ≤ n; 1 ≤ i ≤ [number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order. 



It is guaranteed that the input has at least one query of the third type.

Output

For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.

Examples

Input

4 9
1 4 3
2 4
3 3 1
1 2 3
2 2
3 1 2
1 3 1
2 2
3 1 3


Output

YES
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
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 (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    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;
int n, m;
class LCA {
  int n;
  vector<vector<int>> parent;
  vector<int> depth;
  long long int ans;
  int maxdepth;
  void initdfs(vector<vector<int>> &g, int r, int p, int d) {
    depth[r] = d;
    parent[0][r] = p;
    for (int i = 0; i < (int)(g[r].size()); i++)
      if (g[r][i] != p) initdfs(g, g[r][i], r, d + 1);
  }

 public:
  LCA(vector<vector<int>> &g, int root) {
    n = g.size();
    maxdepth = 0;
    while (n >> maxdepth) maxdepth++;
    parent = vector<vector<int>>(maxdepth + 1, vector<int>(n));
    depth = vector<int>(n);
    parent[0][0] = -1;
    initdfs(g, root, -1, 0);
    for (int k = 0; k < (int)(maxdepth); k++) {
      for (int i = 0; i < (int)(n); i++) {
        if (parent[k][i] < 0)
          parent[k + 1][i] = -1;
        else
          parent[k + 1][i] = parent[k][parent[k][i]];
      }
    }
  }
  long long int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    long long int ans = 0;
    for (int k = 0; k < (int)(maxdepth + 1); k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = ((int)(maxdepth + 1) - 1); k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : 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)]; }
};
struct Query {
  int t, x, y;
  Query(int tt, int xx, int yy) {
    t = tt;
    x = xx;
    y = yy;
  }
};
int main() {
  scanf("%d%d", &n, &m);
  vector<vector<int>> g(n + 1);
  vector<int> par(n, -1);
  vector<vector<pair<int, int>>> ask(m);
  vector<Query> Q;
  for (int i = 0; i < (int)(m); i++) {
    int t, x, y = 0;
    scanf("%d%d", &t, &x);
    x--;
    if (t == 1) {
      scanf("%d", &y);
      y--;
      par[x] = y;
      g[x].push_back(y);
      g[y].push_back(x);
    } else if (t == 2) {
    } else {
      scanf("%d", &y);
      y--;
      ask[y].push_back(pair<int, int>(x, i));
    }
    Q.emplace_back(t, x, y);
  }
  for (int i = 0; i < (int)(n); i++) {
    if (par[i] == -1) {
      g[n].push_back(i);
      g[i].push_back(n);
    }
  }
  LCA lca(g, n);
  UnionFind uf(n);
  int k = 0;
  vector<pair<int, int>> ans;
  for (int i = 0; i < (int)(m); i++) {
    int t = Q[i].t;
    int x = Q[i].x;
    int y = Q[i].y;
    if (t == 1) uf.unionSet(x, y);
    if (t == 2) {
      if (k < ask.size())
        for (__typeof((ask[k]).begin()) to = (ask[k]).begin();
             to != (ask[k]).end(); to++) {
          ans.emplace_back(to->second, (uf.findSet(x, to->first) &&
                                        lca.lca(x, to->first) == to->first));
        }
      k++;
    }
  }
  sort(ans.begin(), ans.end());
  for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); it++)
    puts(it->second ? "YES" : "NO");
  return 0;
}

```