题目地址

http://acm.hdu.edu.cn/showproblem.php?pid=1213

 #include<iostream>
using namespace std;
#define MAX 100005
int fa[MAX]; int findHead(int x)
{
while(x!=fa[x])
x=fa[x];
return x;
} void Union(int x,int y)
{
int fa_x=findHead(x);
int fa_y=findHead(y);
if(fa_x!=fa_y) fa[fa_x]=fa_y;
} int main()
{
int T,N,M,A,B,count;
cin>>T;
while(T--){
count=;
cin>>N>>M;
for(int j=;j<=N;j++) fa[j]=j;
for(int i=;i<M;i++){
cin>>A>>B;
Union(A,B);
}
for(int i=;i<=N;i++)
if(fa[i]==i) count++;
cout<<count<<endl;
}
return ;
}

HDU1213最简单的并查集问题的更多相关文章

  1. hdu1213 How Many Tables 并查集的简单应用

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 简单的并查集 代码: #include<iostream> #include< ...

  2. The Suspects 简单的并查集

    Description 严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁.为了减少传播给别人的机会, 最好的策略是隔离可能的患者. 在Not ...

  3. The Suspects(简单的并查集)

    Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, wa ...

  4. hdu 1182 A Bug's Life(简单种类并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 题意:就是给你m条关系a与b有性关系,问这些关系中是否有同性恋 这是一道简单的种类并查集,而且也 ...

  5. UVA - 1160(简单建模+并查集)

    A secret service developed a new kind of explosive that attain its volatile property only when a spe ...

  6. hdu 1213 (How Many Tables)(简单的并查集,纯模板)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu1213 How Many Tables(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 1213 How Many Tables 简单的并查集问题

    my code: #include <cstdio>#include <cstring>#include<iostream>using namespace std; ...

  9. HDU--1213并查集

    题目传送门:HDU--1213 //题意:ignatius过生日,客人来到,他想知道他需要准备多少张桌子.然而一张桌子上面只能坐上相互熟悉的人, //其中熟悉可定义成为A与B认识,B与C认识,我们就说 ...

随机推荐

  1. Suricata的性能

    不多说,直接上干货! 见官网 https://suricata.readthedocs.io/en/latest/performance/index.html Docs » 7. Performanc ...

  2. window上安装MySQL

    一.安装MySQL 1.1 下载解压缩版的安装包,解压,然后配置环境变量 PATH=.......;D:\Program Files (x86)\mysql-5.5.27-win32\bin (注意是 ...

  3. 外文翻译 《How we decide》被情感愚弄 第三节

    本科论文答辩终于结束啦,一切都要继续回到正轨. 这是第三章章最后一节 书的导言 本章第二节 本章第一节 "信用卡是我的敌人."Herman Palmer这样说到.在平日,Herma ...

  4. 2019/05/11 Java内存结构

    1.  类加载子系统:负责从文件系统或者网络加载Class信息,加载的信息存放在一块称之方法区的内存空间. 2.  方法区:就是存放类的信息.常量信息.常量池信息.包括字符串字面量和数字常量等. 3. ...

  5. AngularJS 表单验证手机号(非必填)

    代码: <form ng-app="myApp" ng-controller="validateCtrl" name="myForm" ...

  6. iOS应用版本更新(自动提醒用户更新代码)

    在#import "AppDelegate.h" 文件中的application:(UIApplication *)application didFinishLaunchingWi ...

  7. MY $MYVIMRC

    set nocompatiblesource $VIMRUNTIME/vimrc_example.vim"source $VIMRUNTIME/mswin.vim"behave m ...

  8. IE8 window.open 不支持此接口 的问题解决

    在使用vs2010调试代码时,突然出现 window.open 不支持此接口的提示,开始认为是不是vs的问题,后来上网查询说是系统问题.我不想重装系统,之后发现是IE的问题,使用其他浏览器浏览系统不会 ...

  9. 原创:E325: ATTENTION vim超完整超给力的问题与解决方法

    又到了老葵花哥哥开课的时间 这是给大家提供一个企业常见的错误 我相信大家生活还编程中会长期使用接触这个错误 这里我们经常用的两个选项 (E)dit any way 编辑原来的文件,忽略刚刚做的修改 ( ...

  10. git 本地与远程仓库出现代码冲突解决方法

    提交过程中报错: [python@heaven-00 Selesystem]$ git push -u origin masterUsername for 'https://github.com': ...