poj1611 the suspects(并查集)
来源:互联网 发布:nginx搭建wss环境 编辑:程序博客网 时间:2024/06/11 00:15
并查集裸题。
#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("%d\n",ans); } return 0;}
阅读全文
0 0
- poj1611 The Suspects(并查集)
- POJ1611 The Suspects (并查集)
- POj1611:The Suspects(并查集)
- 【POJ1611】The Suspects(并查集)
- poj1611 the suspects(并查集)
- POJ1611 The Suspects(并查集)
- POJ1611 The Suspects 并查集求解
- POJ1611 The Suspects 并查集
- poj1611 The Suspects (并查集)
- poj1611-The Suspects--并查集
- 并查集 poj1611 The Suspects
- POJ1611 The Suspects 并查集
- poj1611 The Suspects(基础并查集)
- poj1611 The Suspects 并查集
- POJ1611:The Suspects【并查集】
- poj1611 The suspects 并查集
- 【并查集】:poj1611,The Suspects
- POJ1611 The Suspects(并查集)
- git的一些常用命令
- C++类,构造函数,利用友元判断2个类数据
- 入职第一天,上午完成JBOSS安装配置
- WIN7系统如何与虚拟机Ubuntu系统通过SSH沟通
- python
- poj1611 the suspects(并查集)
- redis统计
- Ubuntu 16.04 (sudo apt-get update)出现:Problem executing scripts APT::Update::Post-Invoke-Success '
- Spark Structured Streaming框架(1)之基本用法
- java:List自定义排序
- 总结-2017/9/4
- Python爬虫实战(一):爬取豆瓣电影top250排名
- c# 插入排序
- 文章标题