30pts求调
#include<bits/stdc++.h>
using namespace std;
const int MAXN=5010;
int father[MAXN];
inline int pFind(int x)
{
if(father[x]==x) return x;
return father[x]=pFind(father[x]);
}
void uunion(int x,int y)
{
if(pFind(x)!=pFind(y)) father[x]=pFind(father[y]);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m,p;
cin>>n>>m>>p;
for(int i=1;i<=n;i++)
{
father[i]=i;
}
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
uunion(a,b);
}
for(int i=0;i<p;i++)
{
int a,b;
cin>>a>>b;
if(pFind(a)==pFind(b))
{
cout<<"Yes\n";
}
else cout<<"No\n";
}
return 0;
}