B - The Suspects -poj 1611
#include<stdio.h> const int maxn = 100005; int f[maxn];
int Find(int x)
{
if(f[x] != x)
f[x] = Find(f[x]);
return f[x];
} int main()
{
int N, M; while(scanf("%d%d", &N, &M), N+M)
{
int i, u, v, T; for(i=0; i<N; i++)
f[i] = i; while(M--)
{
scanf("%d%d", &T, &u);
u = Find(u); while(--T)
{
scanf("%d", &v);
v = Find(v);
f[v] = u;
}
} int ans = 1;
u = Find(0); for(i=1; i<N; i++)
{
if(Find(i) == u)
ans++;
} printf("%d\n", ans);
} return 0;
}
B - The Suspects -poj 1611的更多相关文章
- (并查集)The Suspects --POJ --1611
链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- The Suspects POJ 1611
The Suspects Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, w ...
- C - The Suspects POJ - 1611(并查集)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- poj 1611 The Suspects 解题报告
题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...
- poj 1611 The Suspects(简单并查集)
题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...
- POJ - 1611 The Suspects 【并查集】
题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...
- 【裸的并查集】POJ 1611 The Suspects
http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...
- 并查集 (poj 1611 The Suspects)
原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...
随机推荐
- powerdesigner设置唯一键,但不是主键的方式
[转载]http://blog.csdn.net/cnham/article/details/6676650 唯一约束 唯一约束与创建唯一索引基本上是一回事,因为在创建唯一约束的时候,系统会创建对应的 ...
- PHP 开发API接口 注册,登录,查询用户资料
服务端 <?php require 'conn.php'; header('Content-Type:text/html;charset=utf-8'); $action = $_GET['ac ...
- runnable和thread的区别
一是写一个类继承自Thread类,然后重写里面的run方法,用start方法启动线程二是写一个类实现Runnable接口,实现里面的run方法,用new Thread(Runnable target) ...
- 极端气候频现 五款开发天气预报应用的API
http://www.csdn.net/article/2014-02-07/2818322-weather-forecast-api-for-developing-apps
- Codeforces 527E Data Center Drama(欧拉回路)
题意: 给定一个无向图连通图,把这个的无向边变成有向边,并添加最少的有向边使这个图每个结点的出度为偶数. Solution: 题目很长,并且很多条件说的不太直接,确实不太好懂. 首先先看得到的无向图, ...
- 1. mybatis批量插入数据
通过list <insert id="saveByList" useGeneratedKeys="true" parameterType="ja ...
- cc命令
多数UNIX平台都通过CC调用它们的C编译程序.除标准和CC以外,LINUX和FREEBSD还支持gcc. 基本的编译命令有以下几种: 1. -c 编译产生对象文件(*.obj)而不链接成可执行文件, ...
- overflow第一次觉得你有点可恶
今天用css做下拉菜单,因为不需要做手机自适应,再手机里看起来工整一点就行,可是列表中最后一个li的宽度撑开了父div,导致看起来很糟糕,所以给父元素加overflow:hidden:但是下拉列表也被 ...
- 高德地图关键字搜索删除上一次搜索的Marker
方法:Marker类的 setMap(null);方法 高德是通过循环调用addmarker(i,d)方法 创建marker标记,所以我们需要 把创建的marker标记压入到一个数组,再第二次搜索 ...
- PHP面向对象(OOP):把对象串行化serialize()方法,__sleep()方法,__wakeup()方法
有时候需要把一个对象在网络上传输,为了方便传输,可以把整个对象转化为二进制串,等到达另一端时,再还原为原来的对象,这个过程称之为串行化(也叫序列化), 就像我们现在想把一辆汽车通过轮船运到美国去,因为 ...