#pragma GCC target("avx2") #pragma GCC optimize("Ofast,unroll-loops") #include #include #include using namespace std; constexpr int N_MAX = 20032; int main() { cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; vector P(N); for(int& p : P) { cin >> p; p--; } vector> room(N), friends(N); for(int i = 0; i < N; i++) room[P[i]][i] = 1; while(M--) { int A, B; cin >> A >> B; A--; B--; friends[A][B] = friends[B][A] = 1; } int Q; cin >> Q; while(Q--) { int X, Y; cin >> X >> Y; X--; Y--; if(P[X] == P[Y]) { puts("No"); continue; } if((friends[X] & room[P[Y]]).none()) { puts("No"); continue; } puts("Yes"); room[P[X]][X] = 0; P[X] = P[Y]; room[P[X]][X] = 1; } }