我是靠谱客的博主 忧伤老师,这篇文章主要介绍poj1611 the suspects(并查集),现在分享给大家,希望可以做个参考。

并查集裸题。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<cstdio> #define N 30005 int fa[N],n,m; int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } int main(){ // freopen("a.in","r",stdin); while(1){ int ans=1; scanf("%d%d",&n,&m); if(n==0&&m==0) break; for(int i=0;i<n;++i) fa[i]=i; while(m--){ int k,a,b; scanf("%d%d",&k,&a); for(int i=1;i<k;++i){ scanf("%d",&b); int xx=find(a),yy=find(b); if(xx!=yy) f[yy]=xx; } } for(int i=1;i<n;++i) if(find(i)==find(0)) ans++; printf("%dn",ans); } return 0; }

最后

以上就是忧伤老师最近收集整理的关于poj1611 the suspects(并查集)的全部内容,更多相关poj1611内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部