Ice_cream's world I

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 975    Accepted Submission(s): 567

Problem Description
ice_cream's world is a rich country, it has many fertile lands. Today, the queen of ice_cream wants award land to diligent ACMers. So there are some watchtowers are set up, and wall between watchtowers be build, in order to partition
the ice_cream’s world. But how many ACMers at most can be awarded by the queen is a big problem. One wall-surrounded land must be given to only one ACMer and no walls are crossed, if you can help the queen solve this problem, you will be get a land.
 
Input
In the case, first two integers N, M (N<=1000, M<=10000) is represent the number of watchtower and the number of wall. The watchtower numbered from 0 to N-1. Next following M lines, every line contain two integers A, B mean between
A and B has a wall(A and B are distinct). Terminate by end of file.
 
Output
Output the maximum number of ACMers who will be awarded.

One answer one line.
 
Sample Input
8 10
0 1
1 2
1 3
2 4
3 4
0 5
5 6
6 7
3 6
4 7
 
Sample Output
3
 
Author
Wiskey
 
Source
 
Recommend
威士忌   |   We have carefully selected several similar problems for you:  2118 2119 2121 2117 2115 

好久不写并查集,刚开始以为会是scc什麽的,还好没写- -||

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int pre[10010],n,m,cnt;
void init()
{
for(int i=0;i<10010;i++)
pre[i]=i;
}
int find(int x)
{
return pre[x]==x?x:find(pre[x]);
}
void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fy!=fx)
pre[fy]=fx;
else
cnt++;
}
int main()
{
while(cin>>n>>m)
{
init();
int a,b;
cnt=0;
for(int i=0;i<m;i++)
{
cin>>a>>b;
join(a,b);
}
cout<<cnt<<endl;
}
return 0;
}

hdoj--2120--Ice_cream's world I(并查集判断环)的更多相关文章

  1. HDU - 1272 小希的迷宫(并查集判断环)

    https://cn.vjudge.net/problem/HDU-1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardo ...

  2. HDU 4514 - 湫湫系列故事——设计风景线 - [并查集判无向图环][树形DP求树的直径]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4514 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...

  3. hdoj 1116 Play on Words 【并查集】+【欧拉路】

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)

    题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...

  5. 1021. Deepest Root (25) -并查集判树 -BFS求深度

    题目如下: A graph which is connected and acyclic can be considered a tree. The height of the tree depend ...

  6. poj 3310(并查集判环,图的连通性,树上最长直径路径标记)

    题目链接:http://poj.org/problem?id=3310 思路:首先是判断图的连通性,以及是否有环存在,这里我们可以用并查集判断,然后就是找2次dfs找树上最长直径了,并且对树上最长直径 ...

  7. HDU 4514并查集判环+最长路

    点击打开链接 题意:中文题...... 思路:先推断是否能成环,之前以为是有向图,就用了spfa推断,果断过不了自己出的例子,发现是无向图.并查集把,两个点有公共的父节点,那就是成环了,之后便是求最长 ...

  8. HDU - 4514 湫湫系列故事——设计风景线(并查集判环)

    题目: 随着杭州西湖的知名度的进一步提升,园林规划专家湫湫希望设计出一条新的经典观光线路,根据老板马小腾的指示,新的风景线最好能建成环形,如果没有条件建成环形,那就建的越长越好. 现在已经勘探确定了n ...

  9. A simple problem(并查集判环)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497 题意:给定一些点和边的关系,判断S点是否 ...

随机推荐

  1. Oracle获取alter.log的方法

    10g下:可以在 admin\{sid}\pfile文件下的init.ora文件中找到以下内容:audit_file_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORC ...

  2. 2018最新WordPress缩略图设置方法

    缩略图设置的方法很多,但都不全面,且很多教程已经失效了,其中使用插件来实现,可是那些插件都使用过都不能实现效果,所以我整理了一份使用代码实现缩略图的方法. 1.找到网站根目录/wp-content/t ...

  3. (转)webpack从零开始第6课:在Vue开发中使用webpack

    vue官方已经写好一个vue-webpack模板vue_cli,原本自己写一个,发现官方写得已经够好了,自己写显得有点多余,但为了让大家熟悉webpack,决定还是一步一步从0开始写,但源文件就直接拷 ...

  4. asp、asp.net、ado、ado.net各自区别和联系?

    asp.net与ado.net 的区别? asp.net是微软公司的.Net技术框架下的B/S(网页方向)框架技术.ado.net则是由asp.net编程语言编写的数据访问层的总括..说白了就是:as ...

  5. windows server 2008 不能执行bat

    服务器有一个bat脚本,需要自动或手工执行,之前一直运行OK,可是突然有一天自动或手动都不能执行了,查了半天,原来是因为另一个运维人把环境变量中path的值改了,%SystemRoot%\system ...

  6. 模拟试题A

    模拟试题A 一.单项选择题(2′*12=24′) 1.下面各种坐标变换中,会产生变换前后维度的改变的是( ) A)建模变换 B)观察变换 C)投影变换 D)视口变换 2.下列描述深度缓冲消隐算法的特点 ...

  7. sqlserver 时间测试

    select * from GropBy where [date] BETWEEN '2010-10' and '2015-10' --从字符串转换日期和/或时间时,转换失败. select * fr ...

  8. img-responsive class图片响应式

    在BootStrap中,给<img>添加 .img-responsive样式就可以实现图片响应式. 1 <img src="..." class="im ...

  9. 配置H3C交换机ftp服务

    配置H3C交换机ftp服务,用于与交换机进行文件上传.下载,常用于更新程序上传及配置备份文件下载. 准备工作:三层设备(路由器.三层交换机等)至少一个接口配置IP,二层交换机需配置一个处于UP状态的v ...

  10. MySQL数据库各个版本的区别

    MySQL数据库各个版本的区别 MySQL数据库 MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),MySQL数据库系统使用最常用的数据库管理语言--结构化查询语言(SQL)进行数据库管 ...