~~过样例就能AC吗~~
自己在检查一下吧
by star_magic_young @ 2018-07-04 18:52:44
你写的并查集错了。
我把你的改了一下
```cpp
#include<bits/stdc++.h>
using namespace std;
int father[20005];
int fa,fb,m,n,i,j,x,y,p;
int find(int x)
{
if (father[x]!=x)
father[x]=find(father[x]);
return father[x];
}
int main()
{
cin>>n>>m>>p;
for(i=1;i<=n;i++)
father[i]=i;
for(i=1;i<=m;i++)
{
cin>>x>>y;
fa=find(x);
fb=find(y);
if(fa!=fb)
father[fa]=fb;
//本身就是祖先,你还要找一遍?
}
for(i=1;i<=p;i++)
{
cin>>x>>y;
if(find(x)==find(y))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
```
by wdlht @ 2018-07-04 18:57:41
AC代码
by wdlht @ 2018-07-04 18:58:00
别看我是绿名,我可厉害着呢
by wdlht @ 2018-07-04 18:58:59
一看就看出来了
可能你还不太理解并查集,推荐一篇文章:
https://blog.csdn.net/u013546077/article/details/64509038
by wdlht @ 2018-07-04 19:00:17
@[lihaotian](/space/show?uid=87301)
谢谢dalao
by 诸葛村夫 @ 2018-07-04 19:21:25
@[lihaotian](/space/show?uid=87301) %%%
by 诸葛村夫 @ 2018-07-04 19:21:44