1 #include 2 #include 3 #include 4 const int N=5100; 5 int ai,aj,pi,pj; 6 int m,n,p; 7 int pa[N]; 8 int cha(int k) 9 {10 if(pa[k]!=k)11 {12 pa[k]=cha(pa[k]);13 }14 return pa[k];15 }16 bool bing(int x,int y)17 {18 int x2=cha(x);19 int y2=cha(y);20 if(x2==y2)21 return false;22 pa[y2]=x2;23 return true;24 }25 int main()26 {27 while(scanf("%d%d%d",&n,&m,&p)!=EOF)28 {29 for(int i=0;i<=n;i++)30 {31 pa[i]=i;32 }33 for(int i=1;i<=m;i++)34 {35 scanf("%d%d",&ai,&aj);36 bing(ai,aj);37 }38 for(int i=1;i<=p;i++)39 {40 scanf("%d%d",&pi,&pj);41 if(cha(pi)==cha(pj))42 printf("Yes\n");43 else44 printf("No\n");45 }46 }47 return 0;48 }