为什么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. LOAD TABLE tbl_name FROM MASTER语法 SQL

    用于把表的拷贝从主服务器转移到从属服务器.本语句的主要作用是调试LOAD DATA FROM MASTER.它要求用于连接主服务器的帐户拥有对主服务器的RELOAD和SUPER权限,并拥有对要载入的主 ...

  2. AFN网络状态的时时监控以及网络的判断、

    //3.判断网络状况    AFNetworkReachabilityManager *netManager = [AFNetworkReachabilityManager sharedManager ...

  3. hdu1827 强连通

    题意:一个人需要联系其他所有人,已知他自己联系每个人的花费,并且他可以联系某个人再让他联系他能联系到的人,给出一系列关系表示 A 能够联系 B.问他最少需要联系多少人,花费多少钱 首先,建成一个有向图 ...

  4. Amazon-countDuplicate

    Print the count of duplicate char in a given string in same order. Ex: Input- 'abbaccdbac', Output- ...

  5. Java——集合框架 工具

     /* * Arrays工具类的使用 */ public class ArraysTest { public static void main(String[] args) { // TODO A ...

  6. js获取客户端操作系统

    function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == " ...

  7. C++中的单例模式

    单例模式也称为单件模式.单子模式,可能是使用最广泛的设计模式.其意图是保证一个类仅有一个实例,并提供一个访问它的全局访问点,该实例被所有程序模块共享.有很多地方需要这样的功能模块,如系统的日志输出,G ...

  8. (转) SLAM系统的研究点介绍 与 Kinect视觉SLAM技术介绍

          首页 视界智尚 算法技术 每日技术 来打我呀 注册     SLAM系统的研究点介绍 本文主要谈谈SLAM中的各个研究点,为研究生们(应该是博客的多数读者吧)作一个提纲挈领的摘要.然后,我 ...

  9. javascript this 代表的上下文,JavaScript 函数的四种调用形式

    JavaScript 是一种脚本语言,支持函数式编程.闭包.基于原型的继承等高级功能.其中JavaScript 中的 this 关键字,就是一个比较容易混乱的概念,在不同的场景下,this会化身不同的 ...

  10. linux包之sysstat之sar命令

    要启动SAR,必须通过cron工具以周期性的间隔启动.安装sysstat包后,默认创建一个/etc/cron.d/sysstat文件,其默认内容为:# run system activity acco ...