#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; int main(){ int n, m; cin >> n >> m; vector p(n); for (int i=0; i> p[i]; p[i]--; } vector> ikeru(n, vector(0)); for (int i=0; i> a >> b; a--; b--; ikeru[a].push_back(b); ikeru[b].push_back(a); } int BORDER = 271; vector cnt(n,-1); vector> hav_friend; vector now_world(n); vector> koshin(n, vector(0)); int nowcnt = 0; for (int i=0; i= BORDER){ cnt[i] = nowcnt; hav_friend.emplace_back(vector(n,0)); for (int j : ikeru[i]){ hav_friend[nowcnt][now_world[j]]++; koshin[j].push_back(nowcnt); } nowcnt++; } } int q; cin >> q; for (int i=0; i> x >> y; x--; y--; if (now_world[x] == now_world[y]){ cout << "No\n"; continue; } if (cnt[x] == -1){ bool mode = false; for (int j: ikeru[x]){ if (now_world[j] == now_world[y]){ mode = true; } } if (mode){ cout << "Yes\n"; for (int k:koshin[x]){ hav_friend[k][now_world[x]]--; } now_world[x] = now_world[y]; for (int k:koshin[x]){ hav_friend[k][now_world[x]]++; } }else{ cout << "No\n"; } }else{ if (hav_friend[cnt[x]][now_world[y]] > 0){ cout << "Yes\n"; for (int k:koshin[x]){ hav_friend[k][now_world[x]]--; } now_world[x] = now_world[y]; for (int k:koshin[x]){ hav_friend[k][now_world[x]]++; } }else{ cout << "No\n"; } } } }