【HDUOJ】1213 How many tables
题目链接: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的更多相关文章
- 【整理】mysql中information_schema.tables字段说明
[整理]mysql中information_schema.tables字段说明 2016-05-04 16:47:50| 分类: 默认分类|举报|字号 订阅 下载LOFTER我的照片书 | ...
- 【leetcode】1213.Intersection of Three Sorted Arrays
题目如下: Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a s ...
- 【SQL】175. Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- 【HDUOJ】几道递推DP
就不写题解了.很基础的递推. HDU2084数塔 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 代码: #include <iostre ...
- 【HDUOJ】1257 最少拦截系统
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257 题意:经典题. 题解:最长上升子序列. 代码: #include <iostream> ...
- 【HDUOJ】4280 Island Transport
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到 ...
- [原]Water Water Union-Find Set & Min-Spanning Tree Problems' Set~Orz【updating...】
[HDU] 1213 - How Many Tables [基础并查集,求父节点个数] 1856 -More is better [基础并查集,注意内存,HDU数据水了,不用离散化,注意路径压缩的方式 ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- ios移动输入框被软键盘遮挡
页面输入框会出现被软键盘挡住的问题: 解决方法:获取input点击事件设置body高度 $('input').bind('click',function(e){ var $this = $(this) ...
- Linux内核知识杂记
1.内核调试手段 1.printk打印内核状态 2.产生opps时使用GDB查看调用栈 2.内核空间和用户空间区别,通信方式有哪些? Linux简化了分段机制,使得虚拟地址与线性地址总是一致,因此,L ...
- TI低功耗蓝牙(BLE)介绍【转】
转自:http://blog.csdn.net/ooakk/article/details/7302425 TI低功耗蓝牙(BLE)介绍 本文档翻译和修改自参考资料:CC2540Bluetooth L ...
- drf中间件流程图
- Linux编程获取本机IP地址
使用函数getifaddrs来枚举网卡IP,当中使用到的结构体例如以下所看到的: struct ifaddrs { struct ifaddrs *ifa_next; /* Next item in ...
- C# 编译生成 产生多余的语言包删除"de" "en" "es" "fr" "hu" "it" "ja" "ko" "pr-br" "ro" "pt-br" "ru" "sv" "zh-hans" "zh-hant&qu
VS生成事件 rd /s /q "de" "en" "es" "fr" "hu" "it& ...
- vue中ref的使用(this.$refs获取为undefined)
如果你获取到的总是空的,你注意一下: 1.你在哪里调用,和你调用的对象 试试在mounted()里面调用有效果没有 调用的对象是本来就存在的,还是需要数据渲染之后才会出现的,同理,在mounted() ...
- 网络编程之 OSI七层协议
内容目录: 1.软件开发架构 2.OSI七层协议 3.每层协议介绍 1.软件开发架构 c/s架构: c:客户端 s:服务端 b/s架构: b:浏览器 s:服务器 本质:b/s其实也是c/s 2.OSI ...
- Pregel Worker
- linux常用命令-2网络相关命令
1.ip [选项] 操作对象{link|addr|route...} ip addr show #显示网卡IP信息 2.修改IP配置 1) root权限 2) cd /etc/sy ...