hdoj--2120--Ice_cream's world I(并查集判断环)
Ice_cream's world I
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.
A and B has a wall(A and B are distinct). Terminate by end of file.
One answer one line.
8 10
0 1
1 2
1 3
2 4
3 4
0 5
5 6
6 7
3 6
4 7
3
#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(并查集判断环)的更多相关文章
- HDU - 1272 小希的迷宫(并查集判断环)
https://cn.vjudge.net/problem/HDU-1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardo ...
- HDU 4514 - 湫湫系列故事——设计风景线 - [并查集判无向图环][树形DP求树的直径]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4514 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...
- hdoj 1116 Play on Words 【并查集】+【欧拉路】
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu_5354_Bipartite Graph(cdq分治+并查集判二分图)
题目链接:hdu_5354_Bipartite Graph 题意: 给你一个由无向边连接的图,问对于每一个点来说,如果删除这个点,剩下的点能不能构成一个二分图. 题解: 如果每次排除一个点然后去DFS ...
- 1021. Deepest Root (25) -并查集判树 -BFS求深度
题目如下: A graph which is connected and acyclic can be considered a tree. The height of the tree depend ...
- poj 3310(并查集判环,图的连通性,树上最长直径路径标记)
题目链接:http://poj.org/problem?id=3310 思路:首先是判断图的连通性,以及是否有环存在,这里我们可以用并查集判断,然后就是找2次dfs找树上最长直径了,并且对树上最长直径 ...
- HDU 4514并查集判环+最长路
点击打开链接 题意:中文题...... 思路:先推断是否能成环,之前以为是有向图,就用了spfa推断,果断过不了自己出的例子,发现是无向图.并查集把,两个点有公共的父节点,那就是成环了,之后便是求最长 ...
- HDU - 4514 湫湫系列故事——设计风景线(并查集判环)
题目: 随着杭州西湖的知名度的进一步提升,园林规划专家湫湫希望设计出一条新的经典观光线路,根据老板马小腾的指示,新的风景线最好能建成环形,如果没有条件建成环形,那就建的越长越好. 现在已经勘探确定了n ...
- A simple problem(并查集判环)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497 题意:给定一些点和边的关系,判断S点是否 ...
随机推荐
- java8-2-Lambda表达式
java8的lambda表达式:使得代码更加紧凑:修改方法的能力:更好的支持多核处理(并行处理函数和filter\map\reduce) 例子1: java7中,list集合排序: public st ...
- HTML与CCS(十一)
1.1 HTML介绍 1.1.1 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) s ...
- TypeScript简单的代码片段
TypeScript中,接口.接口实现.函数重载: interface IThing{ name:string; age:number; sayHello:{ (name:string):string ...
- 编译OpenCV遇到Qmake问题
1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...
- (转)RabbitMQ学习之Headers交换类型(java)
http://blog.csdn.net/zhu_tianwei/article/details/40923131 Headers类型的exchange使用的比较少,它也是忽略routingKey的一 ...
- The features of Swift
The features of Swift are designed to work together to create a language that is powerful, yet fun t ...
- js 读取外部的本地json文件
Javascript 读取外部的本地json文件 方案1 运行本地web服务器,提供文件服务 方案2 1.data = '[{"name" : "Ashwin" ...
- python编写简单的html登陆页面(4)
python编写简单的html登陆页面(4) 1 在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将动态态分配数据,建立表格,存放学生信息 2 实现的效果如下: 3 动 ...
- mac安装win10后触摸板没有右键功能键的添加技巧
一些mac用户也会在自己的笔记本电脑上安装windows10系统. 但最近有部分用户发现,安装上win10正式版后,发现无论点击触摸板哪个位置,都只有左键,根本无法右键的问题, 针对此问题,现笔者分享 ...
- bzoj 1192: [HNOI2006]鬼谷子的钱袋 思维_二进制
十分巧妙的一道题. 考虑当前凑出$[1,i/2)$,那么再有一个 $i/2$,就可以凑出 [i/2+1,i). 注意,这里的 $i$ 都是 2 的 $k$ 次幂. 于是,我们只要找到 $i$ 使得 2 ...