- 家族
- 2013-08-29 21:18:57 @
###block code
#include<cstdio>
#define REP(i,l,r) for (int i=l;i<=r;++i)
#define maxn 5001
using namespace std;
int p[maxn],n,m,q;
int ufind(int x){
if (p[x]!=x) p[x]=ufind(p[x]);
return p[x];
}
void uunion(int a,int b){
if (ufind(a)!=ufind(b)) p[ufind(a)]=ufind(b);
}
int main(){
scanf("%d%d%d",&n,&m,&q);
REP(i,1,n) p[i]=i;
REP(i,1,m) {
int c1,c2;
scanf("%d%d",&c1,&c2);
uunion(c1,c2);
}
REP(i,1,q) {
int c1,c2;
scanf("%d%d",&c1,&c2);
if (ufind(c1)==ufind(c2)) printf("Yes\n"); else printf("No\n");
}
return 0;
}
0 条评论
目前还没有评论...