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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class InformationGraph {
    
    static final int MAXN = (int) (1e5 + 5);
    
    int n, m;
    int[] par = new int[MAXN];
    int[][] G;
    
    int time = 0;
    int[] IN = new int[MAXN], OUT = new int[MAXN];
    
    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        
        Arrays.fill(par, -1);
        
        int id = 0, cnt = 0;
        int[] from = new int[m], to = new int[m];
        int[] t = new int[m], x = new int[m], y = new int[m], z = new int[m], u = new int[m], d = new int[m];
        int[] nq = new int[m];
        int tot = 0;
        for (int i = 0; i < m; i++) {
            t[i] = in.nextInt();
            x[i] = in.nextInt() - 1;
            if (t[i] == 1) {
                y[i] = in.nextInt() - 1;
                from[cnt] = y[i];
                to[cnt] = x[i];
                cnt++;
                par[x[i]] = y[i];
            } else if (t[i] == 2) {
                z[i] = id;
                d[id++] = x[i];
            } else {
                u[i] = in.nextInt() - 1;
                nq[u[i]]++;
                tot++;
            }
        }
        
        int qid = 0;
        int[][][] list = new int[id][][];
        for (int i = 0; i < id; i++) list[i] = new int[nq[i]][2];
        for (int i = 0; i < m; i++) {
            if (t[i] == 3) {
                nq[u[i]]--;
                list[u[i]][nq[u[i]]][0] = x[i];
                list[u[i]][nq[u[i]]][1] = qid++;
            }
        }
        
        from = Arrays.copyOf(from, cnt);
        to = Arrays.copyOf(to, cnt);
        G = build_graph(n, from, to);
        
        for (int i = 0; i < n; i++) {
            if (par[i] == -1) {
                dfs(i);
            }
        }
        
        boolean[] res = new boolean[tot];
        UnionFind dsu = new UnionFind(n);
        for (int i = 0; i < m; i++) {
            if (t[i] == 1) {
                dsu.union(x[i], y[i]);
            } else if (t[i] == 2) {
                for (int[] p : list[z[i]]) {
                    int j = p[0], k = d[z[i]], q = p[1];
                    if (dsu.find(j) == dsu.find(k) && IN[j] <= IN[k] && OUT[k] <= OUT[j]) {
                        res[q] = true;
                    }
                }
            }
        }
        
        for(int i=0; i<tot; i++) {
            if(res[i]) out.println("YES");
            else out.println("NO");
        }
    }
    
    static class UnionFind {
        int[] parent;
        
        UnionFind(int n) {
            parent = new int[n];
            Arrays.fill(parent, -1);
        }
        
        int find(int i) {
            if (parent[i] < 0) return i;
            return parent[i] = find(parent[i]);
        }
        
        void union(int i, int j) {
            int x = find(i), y = find(j);
            if (x == y) return;
            if (x > y) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            parent[x] += parent[y];
            parent[y] = x;
        }
    }
    
    void dfs(int u) {
        IN[u] = time++;
        for (int v : G[u]) dfs(v);
        OUT[u] = time++;
    }
    
    
    int[][] build_graph(int n, int[] from, int[] to) {
        int[][] G = new int[n][];
        int[] cnt = new int[n];
        for (int i = 0; i < from.length; i++) {
            cnt[from[i]]++;
        }
        for (int i = 0; i < n; i++) G[i] = new int[cnt[i]];
        for (int i = 0; i < from.length; i++) {
            G[from[i]][--cnt[from[i]]] = to[i];
        }
        return G;
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new InformationGraph().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}
