电波
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 30000
vector<int>q[maxn];
int dfn[maxn],low[maxn],st[maxn],vis[maxn],top;
int num[maxn],i;
void dfs(int u,int deep,int fa){
dfn[u]=deep;
low[u]=deep;
st[++top]=u;
vis[u]=1;
for(int j=0;j<q[u].size();j++){
int v=q[u][j];
if(v==fa) continue;
if(!dfn[v]){
dfs(v,deep+1,u);
low[u]=min(low[u],low[v]);
}else if(vis[v]){
low[u]=min(low[u],low[v]);
}
}
if(low[u]==dfn[u]){
num[u]=++i;
vis[u]=0;
while(st[top]!=u){
num[st[top]]=i;
vis[st[top]]=0,top--;
}
top--;
}
}
int main(){
int n,m;
cin>>n>>m;
memset(vis,0,sizeof(vis));
memset(dfn,0,sizeof(dfn));
for(int j=0;j<m;j++){
int u,v;
scanf("%d%d",&u,&v);
q[u].push_back(v);
q[v].push_back(u);
}
top=0,i=0;
for(int j=1;j<=n;j++){
if(!dfn[j]){
dfs(j,1,j);
}
}
int z;
cin>>z;
for(int j=0;j<z;j++){
int u,v;
scanf("%d%d",&u,&v);
if(num[u]==num[v]){
printf("Yes
");
}else{
printf("No
");
}
}
return 0;
}