#include using namespace std; int main() { int n, q; cin >> n >> q; vector tp; vector> g(n); for (int i = 0; i < n; i++) { int j; cin >> j; if (j == -1) tp.push_back(i); else g[j - 1].push_back(i); } vector tin(n), tout(n); int timer = 0; function dfs = [&](int v) { tin[v] = timer++; for (int to : g[v]) dfs(to); tout[v] = timer++; }; for (int v : tp) dfs(v); while (q--) { int u, v; cin >> u >> v; u--, v--; if (tin[u] <= tin[v] && tout[u] >= tout[v]) cout << "Yes\n"; else cout << "No\n"; } }