并查集 (poj 1611 The Suspects)
原题链接:http://poj.org/problem?id=1611
简单记录下并查集的模板
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
using namespace std;
int fat[];
int finds(int n)
{ //查找
if(fat[n]==n)
return n;
return fat[n]=finds(fat[n]); //路径压缩
}
void join(int a, int b)
{ //合并
int j=finds(a), k=finds(b);
if(j<k)
fat[k]=j;
else
fat[j]=k;
}
int main ()
{
int n,m,i,t,j,k,n2,a,b;
while(scanf("%d %d",&n,&m)&&n+m)
{
for(i=;i<n;++i)
fat[i]=i;
while(m--)
{
scanf("%d %d",&n2,&a);
for(i=;i<n2;++i){
scanf("%d",&b);
join(a,b);
}
}
int sum=;
for(i=;i<n;++i)
if(finds(i)==)
sum++;
printf("%d\n",sum);
}
return ;
}
并查集 (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(并查集,经典题)
		
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
 - 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 (并查集+数组记录子孙个数 )
		
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 24134 Accepted: 11787 De ...
 - POJ 1611 The Suspects (并查集求数量)
		
Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...
 - poj  1611 :The Suspects经典的并查集题目
		
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
 
随机推荐
- Xcode常见路径
			
模拟器安装的位置: /Library/Developer/CoreSimulator/Profiles/Runtimes 可以通过Xcode安装 模拟器程序的沙盒 Xcode编译生成的Product ...
 - Haar分类器方法
			
一.Haar分类器的前世今生 二.人脸检测属于计算机视觉的范畴,早期人们的主要研究方向是人脸识别,即根据人脸来识别人物的身份,后来在复杂背景下的人脸检测需求越来越大,人脸检测也逐渐作为一个单独的研究方 ...
 - Android开发 了解ViewModel
			
前言 ViewModel是google推出的一个数据处理框架,ViewModel类是被设计用来以可感知生命周期的方式存储和管理 UI 相关数据ViewModel中数据会一直存活即使 activity ...
 - [JZOJ3234] 阴阳
			
题目 题目大意 有一棵树,每条边有\(0\)或\(1\)两种颜色. 求满足存在\((u,v)\)路径上的点\(x\)使得\((u,x)\)和\((x,v)\)路径上的两种颜色出现次数相同的点对\((u ...
 - 选择器zuoye
			
代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...
 - System.Web.HttpCookie.cs
			
ylbtech-System.Web.HttpCookie.cs 1.程序集 System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken= ...
 - Git的忽略提交规则
			
相关知识参考资料: https://git-scm.com/book/zh/v2/Git-基础-记录��% 8F%E6%AC%A1%E6%9B%B4%E6%96%B0%E5%88%B0%E4%BB%9 ...
 - HTML基本案列
			
<html> <head> <!-- meta :告诉浏览器,如何翻译汉字 http-equiv :content-type 内容类型 详细内容有后面的值指定 conte ...
 - springmvc 拦截器不拦截jsp,只拦截控制器的访问
			
spring是鼓励把jsp放到WEB-INF文件夹中,然后通过控制器进行访问
 - HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形
			
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...