(并查集)How Many Tables -- HDU --1213
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1213
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/C
代码:
#include<stdio.h>
#include<queue>
#include<stack>
#include<string.h>
using namespace std; #define maxn 1005
#define oo 0xfffffff int n, m;
int f[maxn]; int Find(int x)
{
if(x!=f[x])
f[x]=Find(f[x]);
return f[x];
} int main()
{
int t, i;
scanf("%d", &t);
while(t--)
{
int a, b, fa, fb;
scanf("%d%d", &n, &m); for(i=; i<=n; i++)
f[i]=i; for(i=; i<=m; i++)
{
scanf("%d%d", &a, &b);
fa=Find(a), fb=Find(b); if(fa!=fb)
f[fa]=fb;
} int sum=; for(i=; i<=n; i++)
{
if(f[i]==i)
sum++;
} printf("%d\n", sum);
}
return ;
}
(并查集)How Many Tables -- 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】
PS:做到第四题才发现 2,3题的路径压缩等于没写 How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- (并查集)POJ 1308 & HDU 1325
一开始以为两道题是一样的,POJ的过了直接用相同代码把HDU的交了,结果就悲剧了.最后发现HDU的没有考虑入度不能大于一. 题意:用树的定义来 判断吧,无环,n个结点最多有n-1条边,不然就会有环.只 ...
- [并查集] How Many Tables
题目描述 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants ...
- How Many Tables HDU - 1213
#include<iostream> using namespace std; ; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[ ...
- [kuangbin带你飞]专题五 并查集
并查集的介绍可以看下https://www.cnblogs.com/jkzr/p/10290488.html A - Wireless Network POJ - 2236 An earthquake ...
- 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 ...
随机推荐
- 经典动态规划python实现
1.最长上升子序列 对于一个数字序列,请设计一个复杂度为O(nlogn)的算法,返回该序列的最长上升子序列的长度,这里的子序列定义为这样一个序列U1,U2...,其中Ui < Ui+1,且A[U ...
- tomcat manager
在点击tomcat manager的时候提示以下内容: You are not authorized to view this page. By default the Host Manager is ...
- express.Router
[express.Router] 1.可使用 express.Router 类创建模块化.可挂载的路由句柄.Router 实例是一个完整的中间件和路由系统,因此常称其为一个 “mini-app”. 下 ...
- springmvc后台生成验证码
url http://localhost:8080/admin/getCode http://localhost:8080/admin/checkCode controller package com ...
- 第五章 二叉树(d)二叉树实现
- 84. Largest Rectangle in Histogram (Array, Stack; DP)
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- linux中使用locate搜索文件方法记录
在linux中,有时用apt或者yum等软件包管理工具直接安装软件的时候,不知道软件到底安装到哪里去了,配置文件放哪里?这个时候就可以使用搜索命令locate来找到这些文件.海词上locate翻译为找 ...
- java POI创建Excel示例(xslx和xsl区别 )
Java用来处理office类库有很多,其中POI就是比较出名的一个,它是apache的类库,现在版本到了3.10,也就是2014年2月8号这个版本. 在处理PPT,Excel和Word前,需要导入以 ...
- 什么是springMvc的参数绑定?
参数绑定通俗来讲就是从页面传过来的数据通过SpringMvc进行接收.接收的数据类型可以有: (1)SpringMvc默认支持的类型:request.session.application等. (2) ...
- 解决Pycharm添加虚拟解释器的报错问题
问题背景: 新添加一个virtualenv环境时,需要安装指定的django==1.9.8,但是在添加解释器时,总报一个fuck egg的问题!! 解决方式如下: 1. 2. 3.搞定