链接:

http://poj.org/problem?id=1611

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/B

代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 30005 int a[N];
int n, m; int Find(int x)
{
if(a[x]!=x)
a[x] = Find(a[x]);
return a[x];
} int main()
{ while(scanf("%d%d", &n, &m), n+m)
{
int p, px, py, s, x, y; for(int i=; i<=n; i++)
a[i] = i; for(int i=; i<m; i++)
{
scanf("%d%d", &s, &x); for(int j=; j<s; j++)
{
scanf("%d", &y); px = Find(x);
py = Find(y);
if(px!=py)
a[py] = px;
}
}
int sum=;
p = Find(); for(int i=; i<n; i++)
if(Find(i)==p)
sum++; printf("%d\n", sum); }
return ;
}

最新文章

  1. .net erp(办公oa)开发平台架构概要说明之表单设计器
  2. 在线PDF编辑网站http://www.pdfescape.com
  3. c#分页读取GB文本文件
  4. Type-base dispatch
  5. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
  6. 【Entity Framework 7】 完全不一样的玩法
  7. C++ 数据结构学习一(顺序表)
  8. CSS简单使用
  9. SSM-Spring-10:Spring中cglib动态代理
  10. C语言中return 0和return 1和return -1
  11. Bootstrap如何实现导航条?导航条实例详解
  12. Android PermissionUtils:运行时权限工具类及申请权限的正确姿势
  13. XSY contest1586 proB
  14. Installing TensorFlow on Ubuntu or Windows
  15. Linux基础命令---chsh
  16. filter中的dispatcher解析
  17. hadoop 3.0.0 alpha3 安装、配置
  18. springMVC对简单对象、Set、List、Map的数据绑定和常见问题.
  19. java调用dll或so动态库文件(c++/c)
  20. 前端性能优化-Cookie

热门文章

  1. EXCEL保存提示“隐私问题警告:此文档中包含宏……”解决办法
  2. jenkins systemctl启动失败
  3. Easyui-datagrid显示时间的格式化代码
  4. 整合Spring框架和Hibernate框架
  5. 转---tcp三次握手四次挥手syn fin......
  6. Jmeter元件作用域
  7. google中guava类库:AsyncEventBus
  8. Loitor_产品(一)
  9. 在ecplise中创建一个maven工程
  10. 【D3D】Direct3D中LPRECT(上左右底)和LPoint(x,y)之前转换