http://poj.org/problem?id=1611

【Accepted】

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include <string>
using namespace std;
const int maxn=3e4+;
int fa[maxn];
int n,m;
int a[maxn]; void init()
{
for(int i=;i<n;i++)
{
fa[i]=i;
}
}
int find(int x)
{
return x==fa[x]?x:fa[x]=find(fa[x]);
} void mix(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
fa[fx]=fy;
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)
{
break;
}
init();
for(int i=;i<m;i++)
{
int k;
scanf("%d",&k);
if(k>=)
{
scanf("%d",&a[]);
for(int j=;j<k;j++)
{
scanf("%d",&a[j]);
mix(a[],a[j]);
}
}
}
int sum=;
for(int i=;i<n;i++)
{
if(find(i)==fa[])
{
sum++;
}
}
printf("%d\n",sum);
}
return ;
}

【不太明白】

为啥find(i)==fa[0]能A,fa[i]==fa[0]就是WA。find(0)一定等于fa[0]?

【裸的并查集】POJ 1611 The Suspects的更多相关文章

  1. [并查集] POJ 1611 The Suspects

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

  2. 并查集 (poj 1611 The Suspects)

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

  3. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

  4. POJ 1611 The Suspects(并查集,简单)

    为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了? 题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数. 这是简单并查集应用,所以直接看代码吧! ...

  5. POJ 1611 The Suspects (并查集)

    The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...

  6. poj 1611 The Suspects(并查集)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21598   Accepted: 10461 De ...

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

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

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

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

  9. poj 1611 The Suspects(第一道并查集)

    题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人 ...

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

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

随机推荐

  1. Android Dialogs(4)Dialog事件处理

    Passing Events Back to the Dialog's Host When the user touches one of the dialog's action buttons or ...

  2. 转 Docker和hadoop

    2017-06-21 朱洁 Docker很热,怎么形容?感觉开源除了spark技术,就是docker了,甚至把Go语言也带火了,把Go在TIOBE的排名从百名外带入主流语言的行列. Docker快成救 ...

  3. Hadoop YARN学习之组件功能简述(3)

    Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...

  4. git ---合并和删除分支

    git merge  分支名 //合并子分支到当前分支 git branch -d 分支名//删除分支

  5. Java常用的排序查找算法

    public static void main(String[] args) {      // bubbleSort(); // int[] a = {20,2,10,8,12,17,4,25,11 ...

  6. TCP/UDP套接字 java socket编程实例

    网络协议七层结构: 什么是Socket? socket(套接字)是两个程序之间通过双向信道进行数据交换的端,可以理解为接口.使用socket编程也称为网络编程,socket只是接口并不是网络通信协议. ...

  7. 分享div、text、Box Shadow(阴影)演示及代码的页面

    附图: 直接上链接:www.css88.com/tool/css3Preview/Box-Shadow.html

  8. js 日期时间大小比较

    <body> 开始时间:<input onfocus="setday(this)" id="startTime" name="sta ...

  9. angular2快速开始

    简介 5 分钟从0搭建一个ng2项目demohttps://angular.io/docs/js/latest/quickstart.html 你运气真好,竟然看到了这篇文章,你省事了,一分钟让你完成 ...

  10. 【4412开发板使用经验分享】迅为4412开发板I2C驱动问题

    本文转自迅为论坛:bbs.topeetboard.com 我想写DS3231 的驱动 但是读回的数据老是-6 硬件: 我I2C设备连接的这几个GPIO,看了2.5的手册,接口应该是链接正确的 软件 分 ...