题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213

题意:Ignatius邀请了n个朋友来家里,朋友之间如果互相不认识的不想坐一起,所以至少要准备几张桌子。

题解:啊。裸题。直接输入join一下,然后最后统计同父亲有多少个就行。

代码:

 #include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 1e6+; int f[maxn]; void init(int n){
for(int i = ; i <= n ;i++){
f[i] = i;
}
}
int find(int x){
if( x != f[x]){
f[x] = find(f[x]);
}
return f[x];
}
void join(int a,int b){
int x = find(a);
int y = find(b);
if(x!=y)
f[x]=y;
} bool judge(int x,int y){
x=find(x);
y=find(y);
if(x!=y) return true;
return false;
} int n,m;
int main(){
int T;
cin>>T;
while(T--){
int cnt = ;
cin>>n>>m;
init(n);
int a,b;
for(int i = ; i < m ;i++){
cin>>a>>b;
join(a,b);
}
for(int i = ; i <= n ;i++){
if(f[i] == i){
cnt++;
}
}
cout<<cnt<<endl;
} return ;
}

【HDUOJ】1213 How many tables的更多相关文章

  1. 【整理】mysql中information_schema.tables字段说明

    [整理]mysql中information_schema.tables字段说明 2016-05-04 16:47:50|  分类: 默认分类|举报|字号 订阅     下载LOFTER我的照片书  | ...

  2. 【leetcode】1213.Intersection of Three Sorted Arrays

    题目如下: Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a s ...

  3. 【SQL】175. Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  4. 【HDUOJ】几道递推DP

    就不写题解了.很基础的递推. HDU2084数塔 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 代码: #include <iostre ...

  5. 【HDUOJ】1257 最少拦截系统

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257 题意:经典题. 题解:最长上升子序列. 代码: #include <iostream> ...

  6. 【HDUOJ】4280 Island Transport

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到 ...

  7. [原]Water Water Union-Find Set &amp; Min-Spanning Tree Problems&#39; Set~Orz【updating...】

    [HDU] 1213 - How Many Tables [基础并查集,求父节点个数] 1856 -More is better [基础并查集,注意内存,HDU数据水了,不用离散化,注意路径压缩的方式 ...

  8. 【转】并查集&MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. Idea 导入项目不能运行

    1.项目结构里面配置sdk,配置output输出目录 2.配置语言等级 配置src源文件目录 配置目录里面添加application,添加main class

  2. 拾遗:ssh 公钥连接前的相关准备

    ssh 公钥连接条件: sshd_config 中启用公钥认证 authorized_keys 文件权限必须为 0600 目标用户的 家目录 权限必须为 0700 目标账户必须已设定登陆密码(即处于可 ...

  3. 移动端自动化测试appium 从入门到项目实战Python版✍✍✍

    移动端自动化测试appium 从入门到项目实战Python版 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程 ...

  4. git 常用命令 mv rm checkout revert reset

    关于上节讲的git add 时需要添加注释信息,也可以在git commit时再添加 laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/gi ...

  5. Ubuntu安装mongo可视化工具

    一.robo 3T 是mongodb的一个非常好用的可视化管理工具,曾经名为robomongo,现在被收购后改名为robo 3T.且现在robo 3T 1.1版本能支持mongodb3.4.现在在Ub ...

  6. dubbo源码学习(四):暴露服务的过程

    dubbo采用的nio异步的通信,通信协议默认为 netty,当然也可以选择 mina,grizzy.在服务端(provider)在启动时主要是开启netty监听,在zookeeper上注册服务节点, ...

  7. 关于EntityFramework 更新数据记录时字段全部更新问题和不从数据库中获取直接更新记录

    一.一直对这个比较疑惑感觉只修改一条数据记录的一个字段结果更新Savechages后跟踪生成sql竟然是全部被修改,感觉微软怎么这么傻,总觉得会有其它方式可以只更新部分字段,但一直没有找到相关设置,最 ...

  8. 快速求1~n的k!,k的逆元

    1.求1~n的k! 2.求inv(k!) 3.inv((k-1)!)=inv(k!)*k%mod 4.inv(k)=inv(k!)*((k-1)!)%mod 如 https://www.cnblogs ...

  9. ACM-ICPC 训练平台 & 比赛 分析

    the file can download in https://pan.baidu.com/s/1HwoLFHGAG-boQbIn9xIhxA occ5 the article is also pu ...

  10. 1 visual studio code 配置C++开发环境 (windows 开发环境)

    0 引言 最近帮GF(不幸变成ex了)配置C++开发环境,一开始想给她装个visual studio13完事,但是一想到自己安装以及使用时的诸多麻烦,就有点退却,觉得没有这个必要.正好了解到vscod ...