题目链接:http://poj.org/problem?id=1611

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 30050
#define INF 0x3f3f3f
using namespace std;
int pa[maxn]; int find(int x){
return x == pa[x] ? x : pa[x] = find(pa[x]);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)){
if(!n && !m) break;
for(int i=;i<n;i++) pa[i] = i; for(int i=;i<=m;i++){
int k;
scanf("%d",&k);
if(!k) continue;
int a,b;
scanf("%d",&a);
k--;
while(k--){
scanf("%d",&b);
int ta = find(a);
int tb = find(b);
if(ta != tb){
if(ta < tb) pa[tb] = ta;
else pa[ta] = tb;
}
}
}
int ans = ;
for(int i=;i<n;i++){
if(find(i) == ) ans++;
}
printf("%d\n",ans);
}
}

最新文章

  1. python 安装
  2. 借助node实战JSONP跨域
  3. iOS学习之iOS沙盒(sandbox)机制和文件操作之NSFileManager(三)
  4. UNIX 逐字符输入
  5. Android(Xamarin)之旅(三)
  6. JQuery中的push和join
  7. PNG文件结构分析 ---Png解析
  8. .net-C#代码判断
  9. [Angular 2] Inject Service with &quot;Providers&quot;
  10. java新手笔记16 面积
  11. xargs mv命令使用方法:ls *.mp3 |xargs -i mv {} /tmp
  12. cocos2dx3.1-lua移植android流程
  13. CF #244 D. Match &amp; Catch 后缀数组
  14. angularJS 与angujs-sku实现购物车组合查询
  15. LVDS、CVBS
  16. Linux安装Python3后,如何使用pip命令
  17. Spring容器技术内幕之BeanWrapper类介绍
  18. 18.0-uC/OS-III挂起内核对象
  19. vue-router-2-动态路由配置
  20. 爱今天 APP 闪退怎么办?

热门文章

  1. IOS DLNA开发(CyberLink和PlatinumKit)
  2. iOS 数据持久性存储-属性列表
  3. directsound 应用实例
  4. Java学习----this和super(在继承中)
  5. mysql数据类型——浮点和定点型
  6. yii 验证用户名是否存在 array(&quot;name&quot;,&quot;unique&quot;,&#39;message&#39;=&gt;&#39;用户名已经存在&#39;),
  7. [r]Ubuntu Linux系统下apt-get命令详解
  8. centos 下vmware 下添加硬盘到root
  9. GNU INET SOCKET
  10. 优秀的开发者 vs. 差的开发者