(并查集)The Suspects --POJ --1611
2024-10-18 06:54:29
链接:
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 ;
}
最新文章
- .net erp(办公oa)开发平台架构概要说明之表单设计器
- 在线PDF编辑网站http://www.pdfescape.com
- c#分页读取GB文本文件
- Type-base dispatch
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
- 【Entity Framework 7】 完全不一样的玩法
- C++ 数据结构学习一(顺序表)
- CSS简单使用
- SSM-Spring-10:Spring中cglib动态代理
- C语言中return 0和return 1和return -1
- Bootstrap如何实现导航条?导航条实例详解
- Android PermissionUtils:运行时权限工具类及申请权限的正确姿势
- XSY contest1586 proB
- Installing TensorFlow on Ubuntu or Windows
- Linux基础命令---chsh
- filter中的dispatcher解析
- hadoop 3.0.0 alpha3 安装、配置
- springMVC对简单对象、Set、List、Map的数据绑定和常见问题.
- java调用dll或so动态库文件(c++/c)
- 前端性能优化-Cookie
热门文章
- EXCEL保存提示“隐私问题警告:此文档中包含宏……”解决办法
- jenkins systemctl启动失败
- Easyui-datagrid显示时间的格式化代码
- 整合Spring框架和Hibernate框架
- 转---tcp三次握手四次挥手syn fin......
- Jmeter元件作用域
- google中guava类库:AsyncEventBus
- Loitor_产品(一)
- 在ecplise中创建一个maven工程
- 【D3D】Direct3D中LPRECT(上左右底)和LPoint(x,y)之前转换