【裸的并查集】POJ 1611 The Suspects
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的更多相关文章
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
- 并查集 (poj 1611 The Suspects)
原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
- POJ 1611 The Suspects(并查集,简单)
为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了? 题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数. 这是简单并查集应用,所以直接看代码吧! ...
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- poj 1611 The Suspects(并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21598 Accepted: 10461 De ...
- poj 1611 The Suspects(并查集输出集合个数)
Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...
- poj 1611 The Suspects 并查集变形题目
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 20596 Accepted: 9998 D ...
- poj 1611 The Suspects(第一道并查集)
题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人 ...
- POJ 1611 The Suspects (并查集+数组记录子孙个数 )
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24134 Accepted: 11787 De ...
随机推荐
- 题解报告:hdu 1062 Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...
- 加密解密(4)SSL协议及HTTPS握手过程
SSL协议 简介 SSL (Secure Sockets Layer 安全套接层)是一个安全协议,它提供使用 TCP/IP 的通信应用程序间的隐私与完整性.因特网的 超文本传输协议 (HTTP)使用 ...
- 在面试官问你BS和CS区别的时候如何回答??
这是我下来整理好的,如果哪里不全,望大家多多指教 C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.Inform ...
- Nexus3.0搭建私服上传JAR包 Windows10
背景 近期换了一个项目组,用的是公司自研产品,涉及到很多内部JAR包引用,版本号很多,每次更新都是产品部给出jar包,项目组成员各自复制一套本地替换,来了新人各种安装配置,复杂度太高,这不,我一来,又 ...
- 关于表单清空的细节(reset函数或者class="reset"属性)
在需要清空的表单的情况下, 如果是在页面中 那么就添加属性 class="reset" 也即是 <button class="reset" value= ...
- git 恢复误删的文件
误删的文件如何恢复呢? 执行下面的命令: 1. git reset HEAD a.txt 2. git checkout a.txt 注意:上面两个命令,可以帮我们找回删除的文件,但是对文件内容的修改 ...
- Windows live writer 2012 测试
升级到win10,居然Windows live writer不能用了,装了好久就是装不上去,wlsetup-web.exe 在线安装失败,wlsetup-all.exe离线安装也失败了. 安装Blog ...
- Regular Expression Flavors
Perl https://perldoc.perl.org/perlre.html PCRE http://www.pcre.org/current/doc/html/pcre2syntax.html ...
- CSS3 四边形 凹角写法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C++中何时使用引用
使用引用参数的原因: 程序员能够修改调用函数中的数据对象 通过传递引用而不是整个数据对象,可以提高程序的运行速度. 当数据对象较大时(如结构和类对象),第二个原因最重要,这些也是使用指针参数的原因.这 ...