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 ...
随机推荐
- easyui-datetimebox设置默认时分秒00:00:00
datetimebox默认打开面板显示的是当前的时间,有个需求就是当打开面板时显示固定的”00:00:00”时间, 它本身有个方法spinner方法可以获得时间微调器对象,它所依赖的组件combo有个 ...
- 终端控制类getopt isatty select ttyname
getopt(分析命令行参数) 相关函数 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const argv[ ],con ...
- 2012年及之后的ImageNet比赛的冠军、亚军和季军ImageNet winners after 2012
2012 0.15 - Supervision (AlexNet) - ~ 60954656 params 0.26 - ISI (ensemble of features) 0.27 - LEAR ...
- 【BZOJ】【3239】Discrete Logging
BSGS BSGS裸题,嗯题目中也有提示:求a^m (mod p)的逆元可用快速幂,即 pow(a,P-m-1,P) * (a^m) = 1 (mod p) /******************** ...
- 如何将thick provision lazy zeroed的VMDK文件转换为thick provision eager zeroed?
详细步骤在此: Enabling clustering features for an existing virtual disk by converting in place(1035823) ht ...
- 添加sqljdbc4的maven依赖
sqljdbc是微软sql server的jdbc驱动 使用sqljdbc需要从微软的官方网站下载jar包: http://www.microsoft.com/en-us/download/detai ...
- 从头说catalan数及笔试面试里那些相关的问题 (转)
作者:寒小阳 时间:2013年9月. 出处:http://blog.csdn.net/han_xiaoyang/article/details/11938973. 声明:版权所有,转载请注明出处,谢谢 ...
- [Android系列—] 2. Android 项目文件夹结构与用户界面的创建
前言 在 [Android系列-] 1. Android 开发环境搭建与Hello World 这一篇中介绍了怎样高速搭建Android开发环境, 并成功了建立一个没有不论什么代码更改的 Androi ...
- wireshark 的使用(filter的用法)
转自:http://blog.csdn.net/hanyuxinting/article/details/5558095 过滤器语法---------------------------------- ...
- C语言:strcpy()和memcpy()
一.strcpy和memcpy都是标准C库函数,它们有下面的特点: 1.strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符. ...