- 兵分N路
- 2013-11-29 14:03:34 @
long long
1 条评论
-
shehao1029 LV 7 @ 2013-12-15 09:37:11
#include<iostream>
using namespace std;int father[50002],a,b,m,n,p;
int find(int x)
{
if(father[x]!=x) father[x]=find(father[x]);
return father[x];
}int main()
{
scanf("%d%d%d",&n,&m,&p);
for(int i=0;i<n;i++) father[i]=i;
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);a=find(a);b=find(b);
father[a]=b;
}
for(int i=0;i<p;i++)
{
scanf("%d%d",&a,&b);a=find(a);b=find(b);
if(a==b) printf("yes\n");
else printf("no\n");
}getchar();getchar();
return 0;
}
- 1