【codevs1073】家族
problem
solution
codes
//并查集模板
#include<iostream>
using namespace std;
int fa[5010];
void init(int n){for(int i = 1; i <= n; i++)fa[i]=i;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x, int y){x=find(x);y=find(y);if(x!=y)fa[x]=y;}
int main(){
int n, m, p;
cin>>n>>m>>p;
init(n);
for(int i = 1; i <= m; i++){
int a, b; cin>>a>>b; merge(a,b);
}
for(int i = 1; i <= p; i++){
int a, b; cin>>a>>b;
if(find(a)==find(b))cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}