56 lines
573 B
C++
56 lines
573 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int n,m,p;
|
|
int f[5001];
|
|
|
|
int find(int x)
|
|
{
|
|
if(x==f[x])
|
|
{
|
|
return x;
|
|
}
|
|
return find(f[x]);
|
|
}
|
|
|
|
void merge(int u, int v)
|
|
{
|
|
int fu=find(u);
|
|
int fv=find(v);
|
|
if(fu!=fv)
|
|
{
|
|
f[fu]=fv;
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
cin>>n>>m>>p;
|
|
for(int i=1;i<=n;i++)
|
|
{
|
|
f[i]=i;
|
|
}
|
|
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"<<endl;
|
|
}
|
|
else
|
|
{
|
|
cout<<"No"<<endl;
|
|
}
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|