#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N >> M; vector W(N); vector> F(N); vector> FW(N); vector> memo(N); rep(i,N) cin >> W[i]; rep(i,N) W[i]--; rep(i,M){ int a,b; cin >> a >> b; a--; b--; if(a==b) continue; F[a].pb(b); F[b].pb(a); } rep(i,N){ rep(j,sz(F[i])){ int f = F[i][j]; FW[i].insert(W[f]); if(sz(F[f])>X) memo[i][f] = W[f]; } } return 0; int Q; cin >> Q; while(Q--){ int x,y; cin >> x >> y; x--; y--; if(W[x]==W[y]) cout << "No\n"; else{ int wx = W[x]; int wy = W[y]; vector> err; for(auto m:memo[x]){ if(W[m.first]!=m.second){ err.pb({m.first,W[m.first]}); } } rep(i,sz(err)){ int f = err[i].first; int pre = memo[x][f]; int now = err[i].second; memo[x][f] = now; FW[x].erase(FW[x].find(pre)); FW[x].insert(now); } if(FW[x].find(wy)!=FW[x].end()){ cout << "Yes\n"; W[x] = wy; if(sz(F[x])<=X){ rep(i,sz(F[x])){ int f = F[x][i]; FW[f].erase(FW[f].find(wx)); FW[f].insert(wy); } } } else cout << "No\n"; } } return 0; }