#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; #include int main() { int n, q; cin >> n >> q; atcoder::dsu d(n); rep(i, n) { int p; cin >> p; if (p == -1) continue; d.merge(i, p - 1); } while (q--) { int a, b; cin >> a >> b; --a, --b; cout << (d.same(a, b) ? "Yes" : "No") << endl; } return 0; }