为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了?

题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数。

这是简单并查集应用,所以直接看代码吧!

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int INF=0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
#define fi first
#define se second
#define prN printf("\n")
#define SI(N) scanf("%d",&(N))
#define SII(N,M) scanf("%d%d",&(N),&(M))
#define SIII(N,M,K) scanf("%d%d%d",&(N),&(M),&(K))
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++) int father[30005],mrank[30005]; void init(int n)
{
int i;
for (i=0;i<n;i++)
{
father[i]=i;//并查集是从零开始的
mrank[i]=1;//mrank存的是集合中的个数
}
} int find_set(int x)
{
if (x!=father[x])
{
father[x]=find_set(father[x]);
}
return father[x];
} void myUnion(int x,int y)
{
x=find_set(x);
y=find_set(y);
if (x==y) return; if (mrank[x]>=mrank[y])
{
father[y]=x;
mrank[x]+=mrank[y];
}
else
{
father[x]=y;
mrank[y]+=mrank[x];
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\Zmy\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\Zmy\\Desktop\\out.txt","w",stdout);
#endif // ONLINE_JUDGE
int n,m;
while(cin>>n>>m,n||m)
{
init(n);
int k,fi,se;
for (int i=0;i<m;i++)
{
cin>>k>>fi;
for (int j=1;j<k;j++)
{
cin>>se;
myUnion(fi,se);
}
}
cout<<mrank[father[0]]<<endl;
} return 0;
}

  

POJ 1611 The Suspects(并查集,简单)的更多相关文章

  1. poj 1611 The Suspects(并查集输出集合个数)

    Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...

  2. poj 1611 The Suspects 并查集变形题目

    The Suspects   Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 20596   Accepted: 9998 D ...

  3. POJ 1611 The Suspects (并查集+数组记录子孙个数 )

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24134   Accepted: 11787 De ...

  4. POJ 1611 The Suspects (并查集求数量)

    Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...

  5. POJ 1611 The Suspects 并查集 Union Find

    本题也是个标准的并查集题解. 操作完并查集之后,就是要找和0节点在同一个集合的元素有多少. 注意这个操作,须要先找到0的父母节点.然后查找有多少个节点的额父母节点和0的父母节点同样. 这个时候须要对每 ...

  6. poj 1611 The Suspects 并查集

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 30522   Accepted: 14836 De ...

  7. [ACM] POJ 1611 The Suspects (并查集,输出第i个人所在集合的总人数)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21586   Accepted: 10456 De ...

  8. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

  9. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

随机推荐

  1. 1-3-1 关于API

    主要内容:API函数及其相关内容的介绍.Windows编程相关基础知识介绍 1.API函数的概念 <1>API(Application Programming interface),即应用 ...

  2. 50个C/C++源代码网站(转-清风小阁)

    C/C++是最主要的编程语言.这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码 .主要转贴: http://blog.csdn.net/nuoshueihe/article/detai ...

  3. Unity学习资源

    NGUI文档及视频: http://www.tasharen.com/forum/index.php?topic=6754 动态更新的解决方案: http://game.ceeger.com/foru ...

  4. PowerDesigner的图形工具栏被我关了 怎么才能恢复?就是那个快捷工具栏 图形那个里面有什么放大镜 表 视图什么的

    PowerDesigner的图形工具栏被我关了 怎么才能恢复?就是那个快捷工具栏 图形那个里面有什么放大镜 表 视图什么的   工具-->自定义工具栏-->palette选中

  5. Linux-LVS+keepalived-Testing

    LVS:Linux Virtual Server+++++++++++++Info+++++++++++VIP:172.18.20.222LVS-Master IP:172.18.20.206LVS- ...

  6. 百度ue富文本编辑器setContent方法报错初始化加载内容失败解决办法

    解决方案: 不能创建editor之后马上使用ueditor.setContent('文本内容');要等到创建完成之后才可以使用 ueditor.addListener("ready" ...

  7. 解决json包含html标签无法显示的问题

    要是在json中包含html标签的话,在js接收数据的时候就会出现问题,导致接收失败. 所以在java端,对json包含有html标签的句子先进行转义. package com.alibaba.int ...

  8. mysql5.7.9 源码安装 (转)

    1,安装所有包 yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgc ...

  9. [linux]BASH 的基本语法

    最简单的例子 -- Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1     最简单的例子 -- ...

  10. [mysql] mysql 5.6.X 慢查询日志

    慢查询日志 一篇好文章,学习保存.... 打开慢查询日志 慢查询日志,顾名思义就是记录执行比较慢查询的日志. 查看是否开启慢查询日志: show variables like '%slow%'; 打开 ...