import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int Q = scanner.nextInt();
List<Integer>[] next = new ArrayList[N+1];
List<Integer>[] child = new ArrayList[N+1];
for (int i = 1; i <= N; i++) {
next[i] = new ArrayList<>();
child[i] = new ArrayList<>();
}
for (int i = 0; i < N-1; i++) {
int u = scanner.nextInt();
int v = scanner.nextInt();
next[u].add(v);
}
child[1] = getChild(1,next,child);
for (int i = 0; i < Q; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
if(child[x].contains(y)){
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
public static ArrayList<Integer> getChild(int root, List<Integer>[] next, List<Integer>[] child) {
int len = next[root].size();
for (int i = 0; i < len; i++) {
child[root].addAll(getChild(next[root].get(i),next,child));
}
child[root].add(root);
return (ArrayList<Integer>) child[root];
}
}
并没有完全通过,尽力了