kuangbin_UnionFind C (HDU 1213)
过程模板 扫一下一共有几棵树 输出
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#define MAX 1010
using namespace std;
int father[MAX],table[MAX];
int Findfather(int x)
{
while(x!=father[x])
x=father[x];
return x;
}
void Union(int x,int y)
{
x=Findfather(x);
y=Findfather(y);
father[x]=y;
}
int main()
{
int t,n,m,count;
scanf("%d",&t);
while(t--)
{
count=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
father[i]=i;
table[i]=;
}
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
Union(a,b);
}
for(int i=;i<=n;i++)
{
int tmp=Findfather(i);
bool same=false;
for(int j=;j<=count;j++)
if(tmp==table[j])
{
same=true;
break;
}
if(!same){
table[++count]=tmp;
}
}
printf("%d\n",count);
}
return ;
}
kuangbin_UnionFind C (HDU 1213)的更多相关文章
- 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...
- 并查集---体会以及模板&&How Many Tables - HDU 1213
定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己 ...
- hdu 1213 How Many Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什 ...
- HDU 1213 How Many Tables(模板——并查集)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday ...
- HDU 1213 - How Many Tables - [并查集模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...
- HDU 1213 How Many Tables(并查集模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意: 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,这意味着A,B,C知道对方,所以他们可以 ...
- (并查集)How Many Tables -- HDU --1213
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1213(裸并查集)(无变形)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/ ...
- hdu 1213 How Many Tables(并查集算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/O ...
随机推荐
- java中利用JFrame创建窗体 【转】
1. 一个简单的swing public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame ...
- Listview之优化BaseAdapter中的getView中的contentView
BaseAdapter中getView中改动的地方: @Override public View getView(int position, View contentView, ViewGroup a ...
- 极客DIY:RFID飞贼打造一款远距离渗透利器
本文使用最新的渗透工具RFID飞贼(Tastic RFID Thief)和RFID感应破解技术来获取一些拥有安防的建筑物的访问权限. Tastic RFID Thief是一个无声远距离RFID读卡器, ...
- Python的魔法方法 .
基本行为和属性 __init__(self[,....])构造函数 . 在实例化对象的时候会自动运行 __del__(self)析构函数 . 在对象被回收机制回收的时候会被调用 __str__(sel ...
- JAVA的数组和输入
package com.java1995; import java.util.Scanner; public class Array { public static void main(String[ ...
- BZOJ 2292 永远挑战
最短路. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...
- 用python做些有意思的事——分析QQ聊天记录
####################################### 已更新续集,戳这里. ######################################## 是这样的,有位学 ...
- UI基础:UITableView的编辑和移动
相对UITableViiew进行编辑,必须设置代理,让代理遵循UITableViewDataSource和UITableViewDelegate协议.因为需要代理实现协议中几个必须的方法. UITab ...
- Android Priority Job Queue (Job Manager)(一)
Android Priority Job Queue (Job Manager)(一) 一.为什么要引入Android Priority Job Queue (Job Manager)?如今的A ...
- Android沉浸式(侵入式)标题栏(状态栏)Status(一)
Android沉浸式(侵入式)标题栏(状态栏)Status(一) 现在越来越多的APP设计采用这种称之为沉浸式状态栏(Status)的设计,这种沉浸式状态栏又称之"侵入式"状 ...