【裸的并查集】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 ...
随机推荐
- IOS应用开发版本控制工具之Versions使用,iosversions
Versions版本控制工具破解版(Versions.zip)下载请见本博文附件.下载后在MAC安装完以后,图标是莲花状.见下图: 双击运行如下图: 点击Repository,连接SVN服务器R ...
- 438 Find All Anagrams in a String 找出字符串中所有的变位词
详见:https://leetcode.com/problems/find-all-anagrams-in-a-string/description/ C++: class Solution { pu ...
- Hibernate配置(外部配置文件方式)
配置Hibernate有2种方式,本文讲的是通过外部配置文件配置的方式 Hibernate核心配置文件 <?xml version='1.0' encoding='UTF-8'?> < ...
- ssm基础配置
1.导包 <dependencies> <dependency> <groupId>org.springframework</groupId> < ...
- 将call/apply方法应用于其他对象上的几种方法
在处理类数组中,发现了两种将数组方法应用于类数组的方法,现将call/apply的常用方式总结一下. 一.当做函数调用 function print_vars(var1,var2){ console. ...
- (Nginx+Apache)实现反向代理与负载均衡
反向代理负载均衡 使用代理服务器可以将请求转发给内部的Web服务器,使用这种加速模式显然可以提升静态网页的访问速度.因此也可以考虑使用这种技术,让代理服务器将请求均匀转发给多台内部Web服务器之一上, ...
- CentOS7 Install Shipyard
# 采集木jj 原文:http://www.cnblogs.com/caoguo/p/5735189.html # CentOS7 Install Shipyard# yum install dock ...
- MFC_VS清理器
VS清理器 界面 工程目录 列表控件ID改名IDC_FILELIST 绑定变量m_FileList 属性设置Accept Files 设置True 成员添加 // 用于保存待遍历的目录 vector& ...
- https://quotefancy.com/ 经典句子(英语) 真是特别好~
https://quotefancy.com/ 经典句子(英语)
- 【Hadoop】一、分布式数据库HBase简介
1.分布式数据库特点 说到数据库,我们最熟悉的是类似于mysql这样的关系型数据库,称为RDBMS.关系型数据库作为一种数据存储和数据检索的关键技术,它支持SQL语言的结构化查询,但是它天生不是为 ...