kuangbin_UnionFind B (POJ 1611)
过程是模板 merge完后扫一下几个跟0同祖先节点就是答案了
- #include <iostream>
- #include <string>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <queue>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- const int MAX=;
- int father[MAX];
- int findfather(int x)
- {
- while(x!=father[x])
- x=father[x];
- return x;
- }
- void merge(int x,int y)
- {
- x=findfather(x);
- y=findfather(y);
- if(x!=y) father[x]=y;
- }
- int main()
- {
- int n,m;
- while(scanf("%d%d",&n,&m),n||m)
- {
- int ans=;
- for(int i=;i<n;i++)
- father[i]=i;
- while(m--)
- {
- int k,fir,tmp;
- scanf("%d%d",&k,&fir);
- k--;
- while(k--)
- {
- scanf("%d",&tmp);
- merge(fir,tmp);
- }
- }
- int ex=findfather();
- for(int i=;i<n;i++)
- if(findfather(i)==ex) ans++;
- printf("%d\n",ans);
- }
- return ;
- }
(似乎这个时候代码还很丑)
kuangbin_UnionFind B (POJ 1611)的更多相关文章
- poj 1611(并查集)
http://poj.org/problem?id=1611 题意:有个学生感染病毒了,只要是和这个学生接触过的人都会感染,而和这些被感染者接触的人,也会被感染,现在给定你一些协会的人数,以及所在学生 ...
- poj 1611 The Suspects 解题报告
题目链接:http://poj.org/problem?id=1611 题意:给定n个人和m个群,接下来是m行,每行给出该群内的人数以及这些人所对应的编号.需要统计出跟编号0的人有直接或间接关系的人数 ...
- poj 1611 The Suspects(简单并查集)
题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- (并查集)The Suspects --POJ --1611
链接: http://poj.org/problem?id=1611 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- POJ - 1611 The Suspects 【并查集】
题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...
- 【裸的并查集】POJ 1611 The Suspects
http://poj.org/problem?id=1611 [Accepted] #include<iostream> #include<cstdio> #include&l ...
- 并查集 (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: 35206 Accepted: 17097 De ...
随机推荐
- Twitter CEO:有望进军中国 不会改变原则
新浪科技讯 8月12日下午消息,据台湾“中央社”报道,Twitter CEO科斯特洛(Dick Costolo)日前接受<日经新闻>专访时指出,Twitter有望进军中国大陆,科斯特洛表示 ...
- python解无忧公主的数学时间097.py
python解无忧公主的数学时间097.py """ python解无忧公主的数学时间097.py codegay 2016年3月30日 00:17:26 http:// ...
- VS2013开发Android App 环境搭建
下载并安装vs2013,(安装时发现多了with blend,百度后有人说是设计师用版本,这是不对的,害我花费不少时间查找程序员用版本).我安装的是Microsoft Visual Studio Ul ...
- 理解Mach Port
参考文档: 1. http://robert.sesek.com/thoughts/2012/1/debugging_mach_ports.html 2. Mach 3 Kernel Interfac ...
- PED结构获取进程路径和命令行地址
1.FS寄存器 2.进入FS寄存器地址,7FFDD000 3.偏移30为PED结构 4.偏移地址10 3C,44偏移:路径地址,命令行地址 // 通过PEB结构去查找所有进程模块 void *PEB ...
- 另类加载dll---快捷方式启动参数
http://blogs.360.cn/360safe/2014/08/29/cnc_trojan_and_fake_proto/ 原文: BMP1和BMP2是两个lnk文件(快捷方式),我们知道bm ...
- iOS APP上线流程
前言:作为一名IOS开发者,把开发出来的App上传到App Store是必须的.下面就来详细介绍下具体流程. 1.打开苹果开发者中心:https://developer.apple.com 打开后点击 ...
- LITTLE SHOP OF FLOWERS_DP
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20802 Accepted: 9613 Description You ...
- Logger日志打印普通方法
using System; using System.IO; using System.Text; namespace Core { public class LogHelper { private ...
- Cryptography加密和解密
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Se ...