亲戚
#include<iostream>
using namespace std;
int m,n;
int father[10000];
int find(int x)
{
while(father[x]!=x) x=father[x];
return x;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
father[i]=i;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
int r1=find(x);
int r2=find(y);
if(r1!=r2) father[r2]=r1;
}
int p;
cin>>p;
int a[p+1],b[p+1];
for(int i=1;i<=p;i++)
{
int x,y;
cin>>x>>y;
a[i]=x;b[i]=y;
}
for(int i=1;i<=p;i++)
{
if(find(a[i])==find(b[i]))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}