hdoj--2120--Ice_cream's world I(并查集判断环)
来源:互联网 发布:农业网络信息 版面费 编辑:程序博客网 时间:2024/05/17 01:25
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.
One answer one line.
Sample Input
8 100 11 21 32 43 40 55 66 73 64 7
Sample Output
3
Author
Wiskey
Source
HDU 2007-10 Programming Contest_WarmUp
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;elsecnt++;}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;}
0 0
- hdoj--2120--Ice_cream's world I(并查集判断环)
- HDOJ 2120 Ice_cream's world I(并查集)
- HDOJ 2120 Ice_cream's world I(并查集)
- HDOJ 2120 Ice_cream's world I(并查集判断成环)
- HDOJ Ice_cream's world I 2120【并查集判断成环】
- HDOJ 2120 Ice_cream's world I (并查集)
- hdoj 2120 Ice_cream's world I 【并查集判断成环数】
- hdoj 2120 Ice_cream's world I 【并查集判断成环数】
- hdu 2120 Ice_cream's world I(判断是否有环,简单的并查集)
- HDOJ题目2120 Ice_cream's world I(并查集)
- Ice_cream's world I hdu 2120 并查集判断环
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】
- hdoj 2120 Ice_cream's world I 【判断成环】
- HDOJ 2120 Ice_cream's world I【判断环的个数】
- hdu 2120 Ice_cream's world I (简单并查集 + 判环)
- 【HDU】-2120-Ice_cream's world I(并查集,环)
- HDU:2120 Ice_cream's world I(并查集+统计环的个数)
- 【慕课笔记】第三章 常用的运算符 第4节 JAVA中的比较运算符
- 浅析C++智能指针
- Android WiFi P2P
- 改变状态栏字体颜色
- HDU2083简易版之最短距离
- hdoj--2120--Ice_cream's world I(并查集判断环)
- 在OS X上 为什么su命令的password输入之后 总是提示Sorry?
- 对一个简单豆瓣电影TOP100爬虫的学习
- 【学习笔记】《STL使用入门教程》第五讲:容器map、multimap
- iOS(四)动漫App:五
- 【杭电oj】1040 - As Easy As A+B (快排,巨水)
- Linux中 本地时间获取
- 管理数据库和表
- Android中的OAuth2.0——QQ第三方授权登录