#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int N, M; vector P; vector A, B; int Q; vector X, Y; constexpr int MAX_N = 20'010; bitset uss[MAX_N]; bitset adj[MAX_N]; int main() { for (; ~scanf("%d%d", &N, &M); ) { P.resize(N); for (int i = 0; i < N; ++i) { scanf("%d", &P[i]); --P[i]; } A.resize(M); B.resize(M); for (int i = 0; i < M; ++i) { scanf("%d%d", &A[i], &B[i]); --A[i]; --B[i]; } scanf("%d", &Q); X.resize(Q); Y.resize(Q); for (int q = 0; q < Q; ++q) { scanf("%d%d", &X[q], &Y[q]); --X[q]; --Y[q]; } #ifdef LOCAL for (int x = 0; x < N; ++x) uss[x].reset(); for (int u = 0; u < N; ++u) adj[u].reset(); #endif for (int u = 0; u < N; ++u) uss[P[u]][u] = true; for (int i = 0; i < M; ++i) { adj[A[i]][B[i]] = true; adj[B[i]][A[i]] = true; } auto ps = P; for (int q = 0; q < Q; ++q) { const int x = X[q], y = Y[q]; auto solve = [&]() -> bool { if (ps[x] == ps[y]) return false; return (uss[ps[y]] & adj[x]).any(); }; if (solve()) { puts("Yes"); uss[ps[x]][x] = false; ps[x] = ps[y]; uss[ps[x]][x] = true; } else { puts("No"); } } } return 0; }