POJ----The Suspects
Time Limit: 1000MS | Memory Limit: 20000K | |
Total Submissions: 18890 | Accepted: 9150 |
Description
Input
Output
Sample Input
100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
200 2
1 5
5 1 2 3 4 5
1 0
0 0
Sample Output
4
1
1
Source
#include<iostream>
#include<cstdio>
#define maxn 30002
using namespace std;
int Father[maxn],rank[maxn];
void makeset(int n) //初始化
{
for(int i=;i<n;i++)
{
Father[i]=i; //以自身做根
rank[i]=; //开始高度为1
}
}
int findset(int x)
{
if(x!=Father[x])
{
Father[x]=findset(Father[x]);
}
return Father[x];
} void unionset(int fx,int fy)
{
fx=findset(Father[fx]);
fy=findset(Father[fy]);
if(fx==fy)
return ;
if(rank[fx]>rank[fy])
{
Father[fy]=fx;
rank[fx]+=rank[fy];
}
else
{
Father[fx]=fy;
rank[fy]+=rank[fx];
}
}
int main()
{
int n,m,k,st,num;
while(scanf("%d%d",&n,&m),n+m)
{
makeset(n);
while(m--)
{
scanf("%d%d",&k,&st);
while(--k)
{
scanf("%d",&num);
unionset(st,num);
}
}
printf("%d\n",rank[findset()]);
}
return ;
}
POJ----The Suspects的更多相关文章
- POJ——1611The Suspects(启发式并查集+邻接表)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 31100 Accepted: 15110 Descri ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
- poj 1611 The Suspects 解题报告
题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...
- poj 1611 The Suspects 并查集
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 30522 Accepted: 14836 De ...
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- poj 1611 The Suspects(简单并查集)
题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...
- The Suspects(POJ 1611 并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 30158 Accepted: 14665 De ...
- poj 1611 The Suspects(并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21598 Accepted: 10461 De ...
随机推荐
- 21.重入锁ReentrantLock
ReentrantLock 重入锁,在需要进行代码同步部分上加锁,但是一定要记得解锁. 类型:公平锁(队列方式进行排队).非公平锁(按照cpu的分配),非公平锁性能要比公平锁性能高,默 ...
- 【BZOJ】【2219】数论之神
中国剩余定理+原根+扩展欧几里得+BSGS 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: LL Get_yu ...
- iOS: 音效和音乐的播放,封装的工具类
在iOS中音频播放从形式上可以分为音效播放和音乐播放.前者主要指的是一些短音频播放,通常作为点缀音频,对于这类音频不需要进行进度.循环等控制.后者指的是一些较长的音频,通常是主音频,对于这些音频的播放 ...
- ING【转载】处理大并发系列
一直在处理高可用高并发的服务.看到网上有一个系列的文章,写的不错.跟进一下. 一:http://blog.csdn.net/feitianxuxue/article/details/8936802 二 ...
- Linux文件实时同步,可实现一对多
说明:该功能服务端安装sersync2,客户端安装rsync,原理就是服务端主动推送设定目录下的所有更新的文件到各个客户端rsync接收. rsync大家都知道,是Linux自带的数据同步工具,而se ...
- .Net应用程序打包部署总结
编译源代码并完成测试以后,开发过程其实并没有结束.在这个极端,需要把应用程序提供给用户.无论是ASP.NET应用程序,客户端应用程序还是 Compact Framework构建的应用程序,开发出来的软 ...
- Android -- 点击双下返回退出程序
背景 现在好多apk ...
- VS2008:Failed to return new Code Element
VS2008添加自动化类,报错: [解决方法1] This can be fixed by installing SP1. Please see https://connect.microsof ...
- 【Nodejs】“快算24”扑克牌游戏算法 1.02
快算24是一种挺好的锻炼孩子算数能力的扑克牌游戏,它的游戏方式是把四张牌的牌面数值通过有限四则运算得到结果24,四张牌必须仅用一次.各地玩法还有点差别,有的只算1-10,其它抽出来:有的地方把整幅牌都 ...
- Roo中的@Version
首页 关于 Roo中的@Version 发表回复 问题提出 当我们为entity添加@RooJpaActiveRecord注解时,Roo为我们自动生成了一个名为Entity_Roo_Jpa_Entit ...