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.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE1 solver = new TaskE1();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE1 {

    Graph tree;
    boolean[] isRoot;
    int cTime;
    int[] timeIn;
    int[] timeOut;
    int[] guyWithDoc;
    int[] timeSigned;
    int[][] par;
    int[][] maxTable;
    int[] color;
    int curColor = 1;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int nQueries = in.nextInt();
        Query[] queries = new Query[nQueries];
        for (int i = 0; i < nQueries; ++i) queries[i] = new Query(in);
        tree = new Graph();
        tree.initGraphWithCost(n, n-1);
        isRoot = new boolean[n];
        Arrays.fill(isRoot, true);
        color = new int[n];
        for (int i = 0; i < nQueries; ++i) {
            if (queries[i].type == 1) {
                tree.addDirectEdgeWithCost(queries[i].y - 1, queries[i].x - 1, i);
                isRoot[queries[i].x - 1] = false;
            }
        }
        timeIn = new int[n];
        timeOut = new int[n];
        par = new int[n][20];
        maxTable = new int[n][20];
        ArrayUtils.fill(par, -1);

        for (int i = 0; i < n; ++i) {
            if (isRoot[i]) {
                dfs(i, -1, 0);
                ++curColor;
            }
        }
        guyWithDoc = new int[nQueries + 1];
        timeSigned = new int[nQueries + 1];

        int curDocument = 1;
        for (int qNumber = 0; qNumber < nQueries; ++qNumber) {
            if (queries[qNumber].type == 2) {
                guyWithDoc[curDocument] = queries[qNumber].x-1;
                timeSigned[curDocument] = qNumber;
                ++curDocument;
            } else if (queries[qNumber].type == 3) {
                int documentId = queries[qNumber].y;
                int id = queries[qNumber].x - 1;
                int guy = guyWithDoc[documentId];
                if (guy == id) {
                    out.println("YES");
                    continue;
                }
                if (!isParent(id, guy)) {
                    out.println("NO");
                    continue;
                }
                int max = getMax(guy, id);
                if (max > timeSigned[documentId]) {
                    out.println("NO");
                    continue;
                }
                out.println("YES");
            }
        }
    }

    int getMax(int from, int to) {
        int max = 0;
        for (int i = 19; i >= 0; --i) {
            if (par[from][i] == -1) continue;
            if (!isParent(par[from][i], to)) {
                max = Math.max(max, maxTable[from][i]);
                from = par[from][i];
            }
        }
        max = Math.max(max, maxTable[from][0]);
        return max;
    }

    boolean isParent(int parent, int child) {
        if (color[parent] == color[child]) {
            if (timeIn[parent] <= timeIn[child] && timeOut[parent] >= timeOut[child]) {
                return true;
            }
        }
        return false;
    }

    void dfs(int v, int p, int cost) {
        color[v] = curColor;
        timeIn[v] = cTime++;

        par[v][0] = p;
        maxTable[v][0] = cost;
        for (int i = 1; i < 20; ++i) {
            int par2 = par[v][i-1];
            if (par2 == -1) break;
            if (par[par2][i-1] != -1) {
                par[v][i] = par[par2][i-1];
                maxTable[v][i] = Math.max(maxTable[v][i-1], maxTable[par2][i-1]);
            }
        }
        for (int i = tree.first[v]; i != -1; i = tree.next[i]) {
            dfs(tree.to[i], v, tree.cost[i]);
        }
        timeOut[v] = cTime;
    }

    class Query {
        int type;
        int x, y;

        public Query(InputReader in) {
            type = in.nextInt();
            if (type == 2) {
                x = in.nextInt();
            } else {
                x = in.nextInt();
                y = in.nextInt();
            }
        }
    }
}

class Graph {
    public int[] from;
    public int[] to;
    public int[] first;
    public int[] next;
    public int[] cost;
    public int nVertex;
    public int nEdges;
    public int curEdge;

    public Graph() {}

    public void initGraphWithCost(int n, int m) {
        curEdge = 0;
        nVertex = n;
        nEdges = m;
        from = new int[m * 2];
        to = new int[m * 2];
        first = new int[n];
        next = new int[m * 2];
        cost = new int[m * 2];
        Arrays.fill(first, -1);
    }

    public void addDirectEdgeWithCost(int a, int b, int c) {
        next[curEdge] = first[a];
        first[a] = curEdge;
        to[curEdge] = b;
        from[curEdge] = a;
        cost[curEdge] = c;
        ++curEdge;
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class ArrayUtils {

    public static void fill(int[][] f, int value) {
        for (int i = 0; i < f.length; ++i) {
            Arrays.fill(f[i], value);
        }
    }

}

