n, q = map(int, input().split()) p = [pi - 1 if pi > 0 else i for i, pi in enumerate(map(int, input().split()))] for i in range(n): j = i while p[j] != j: j = p[j] while i != j: ni = p[i] p[i] = j i = ni for _ in range(q): a, b = map(int, input().split()) print('Yes' if p[a - 1] == p[b - 1] else 'No')