题目链接: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. CSS:CSS 图像透明/不透明

    ylbtech-CSS:CSS 图像透明/不透明 1.返回顶部 1. CSS 图像透明/不透明 使用CSS很容易创建透明的图像. 注意:CSS Opacity属性是W3C的CSS3建议的一部分. 更多 ...

  2. git分布式版本控制系统权威指南学习笔记(四):git reset

    文章目录 git reset目录树重写 git reset 重置 git reset目录树重写 git reset --soft 暂存区工作区不变 git reset --hard git reset ...

  3. 【Java多线程系列五】列表类

    一些列表类及其特性  类 线程安全 Iterator 特性 说明 Vector 是 fail-fast 内部方法用synchronized修饰,因此执行效率较低 1. 线程安全的列表类并不意味着调用它 ...

  4. Java门面模式(或外观模式)

    门面模式(或外观模式)隐藏系统的复杂性,并为客户端提供一个客户端可以访问系统的接口. 这种类型的设计模式属于结构模式,因为此模式为现有系统添加了一个接口以隐藏其复杂性.门面模式涉及一个类,它提供客户端 ...

  5. json传参报错

    restful接口报错: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('e' (code 101)): w ...

  6. 二维码APP后台开发记录

    先是搭建环境,我们采用spring4.2.1+hibernate5.0.1进行搭建,从官网上下载框架必用jar包. 在MyEclipse里,创建web项目,创建lib包,将相关jar包放入,别忘了my ...

  7. java访问https绕过证书信任

    package com.xing.test; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

  8. fork执行一个进程

    https://coolr321.github.io/2018/10/30/%E4%B8%80%E4%B8%AAfork-%E8%B0%83%E7%94%A8%E7%9A%84%E4%BE%8B%E5 ...

  9. Dubbo支持的注册中心有哪些?

    1.Dubbo协议(官方推荐协议) 优点: 采用NIO复用单一长连接,并使用线程池并发处理请求,减少握手和加大并发效率,性能较好(推荐使用) 缺点: 大文件上传时,可能出现问题(不使用Dubbo文件上 ...

  10. Web响应的提高

    想象一下,如果用户在页面上触发一个点击事件,结果反应延迟比较明显,这将是一个令人沮丧的事情.而造成这个问题的原因就是响应延迟. 浏览器UI 线程 大家都知道浏览器的UI线程,大多数浏览器都是一个独立的 ...