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. BZOJ 2324 (有上下界的)费用流

    思路: 先跑一遍Floyd  更新的时候map[i][j]=map[i][k]+map[k][j]  k需要小于i或j 正常建边: 把所有点 拆点-> i,i+n add(x,y,C,E)表示x ...

  2. Java 系列之spring学习--注解(三)

    一.注解 使用注解之前要开启自动扫描功能 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...

  3. caffe学习笔记--跑个SampleCode

    Caffe默认情况会安装在CAFFERROOT,就是解压到那个目录,例如: home/username/caffe-master, 所以下面的工作,默认已经切换到了该工作目录.下面的工作主要是,用于测 ...

  4. Kattis - Game Rank

    Game Rank Picture by Gonkasth on DeviantArt, cc by-nd The gaming company Sandstorm is developing an ...

  5. pycharm一些快捷键

    1.鼠标方法在内建函数上,Ctrl+B,看内建函数的定义 2.pycharm单行和多行注释快捷键   单多行注释就一个组合键:选中+Ctrl+/ 3.Python代码块批量添加Tab缩进    按Ta ...

  6. 如何在IE11中设置兼容模式?设置的具体方法

    IE11浏览器软件版本:简体中文正式版 For Win7网络工具立即查看 1.同样进入需要兼容性模式的网站,点击菜单栏位工具--F12开发者人员工具!如下图所示. 2.在开发者选项左下侧菜单栏位,点击 ...

  7. JS 100以内的质数、只能被1和自己整除

    for(var i = 2;i <= 100;i++){ var biao = 1; for(var j = 2;j < i;j++){ if(i%j == 0){ biao = 0; } ...

  8. [SCOI2008]奖励关_状压动归_数学期望

    Code: #include<cstdio> #include<algorithm> using namespace std; const int maxn = 20; dou ...

  9. 路飞学城Python-Day77

    11-DIY一个web框架3 web框架 yuan功能总结 main.py: 启动文件,封装了socket 1 urls.py: 路径与视图函数映射关系 ---- url控制器 2 views.py ...

  10. 【真·干货】MySQL 索引及优化实战

    热烈推荐:超多IT资源,尽在798资源网 声明:本文为转载文章,为防止丢失所以做此备份. 本文来自公众号:GitChat精品课 原文地址:https://mp.weixin.qq.com/s/6V7h ...