def top(train, etoigne): while train[etoigne] != -2: etoigne = train[etoigne] return etoigne def solve(N, Q, P, AB): ans = [] memo = {} for ai, bi in AB: if ai not in memo: memo[ai] = top(P, ai) if bi not in memo: memo[bi] = top(P, bi) ans.append(memo[ai] == memo[bi]) return ans N, Q = [int(x) for x in input().split()] P = [int(x) - 1 for x in input().split()] AB = [[int(x) - 1 for x in input().split()] for _ in range(Q)] [print("Yes" if x else "No") for x in solve(N, Q, P, AB)]