Ice_cream's world I

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 839    Accepted Submission(s):
488

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
 
注意:这是一个求总共有多少环(环内有节点的不算),我们可以利用判断两节点的根节点是否相同来判断!
 
 
 
 
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 10010
using namespace std; int per[maxn],sum;
void init()
{
int i;
for(i=;i<maxn;i++)
{
per[i]=i;//初始化数组
}
}
int find(int x)//查找根节点
{
int t=x;
while(t!=per[t])
t=per[t];
return t;
}
void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx==fy)
sum++;//环的个数
else
per[fx]=fy;
}
int main()
{
int a,b,i,m,n;
while(scanf("%d%d",&a,&b)!=EOF)
{
init();
sum=;
for(i=;i<b;i++)
{
scanf("%d%d",&m,&n);
join(m,n);
}
printf("%d\n",sum);
}
return ;
}
 
 

Ice_cream's world I--hdu2120的更多相关文章

  1. 【HDU2120】Ice_cream's world I(并查集基础题)

    查环操作,裸题.一次AC. #include <iostream> #include <cstring> #include <cstdlib> #include & ...

  2. A - Ice_cream’s world III

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  3. hdu 2120 Ice_cream's world I

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2120 Ice_cream's world I Description ice_cream's worl ...

  4. HDU 2121 Ice_cream’s world II 不定根最小树形图

    题目链接: 题目 Ice_cream's world II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  5. hdoj 2120 Ice_cream's world I【求成环数】

    Ice_cream's world I Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. hdoj 2122 Ice_cream’s world III

    并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  7. Ice_cream’s world III--2122

    Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. Ice_cream's world I

    Ice_cream's world I Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. Ice_cream’s world III(prime)

    Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

随机推荐

  1. [Javascript]史上最短的IE浏览器判断代码

    今天发现个很有趣的js判断全世界最短的代码,想想之前自己写的判断ie浏览器的,这个实在简单多了 var ie = !+"\v1"; 仅仅需要7bytes!参见这篇文章,<32 ...

  2. 网关协议学习:CGI、FastCGI、WSGI、uWSGI

    一直对这四者的概念和区别很模糊,现在就特意梳理一下它们的关系与区别. CGI CGI即通用网关接口(Common Gateway Interface),是外部应用程序(CGI程序)与Web服务器之间的 ...

  3. 理解Python中的装饰器

    文章先由stackoverflow上面的一个问题引起吧,如果使用如下的代码: @makebold @makeitalic def say(): return "Hello" 打印出 ...

  4. 三星S5驱动安装

    三星S5的驱动安装一定要先用原装的数据线链接电脑,在电脑里面安装完驱动之后,以后才能每次都用正常的数据线链接 不然的话会提示某些驱动安装不正常..

  5. Ubuntu14.0.4 64位安装ADT问题

    将ADT 解压之后,新建Android工程后没有R文件: google之后说要安装 ia32-libs 提示如下: 安装lib32z1 安装完成后,再次新建工程,报错如下: 编译存在问题:则继续安装以 ...

  6. C# 调用 Web Service

    Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术.是:通过SOAP ...

  7. 【转】ARM交叉编译工具链

    原文网址:http://www.veryarm.com/cross-tools 为什么要用交叉编译器? 交叉编译通俗地讲就是在一种平台上编译出能运行在体系结构不同的另一种平台上的程序,比如在PC平台( ...

  8. 正则表达式小试牛刀--匹配我的csdn博文标题

    正则表达式小试牛刀--匹配我的博文标题 作者:vpoet 邮箱:vpoet_sir@163.com 正则匹配,我以我的博客页面的博客标题为例:http://blog.csdn.net/u0130187 ...

  9. kindeditor在sae上传文件修改,适合php

    kindeditor在sae上传文件修改,适合php 当前位置: 首页  > 论坛  > 经验共享 用户登录   新用户注册   主题: kindeditor在sae上传文件修改,适合ph ...

  10. Java如何访问Axis2服务端

    import javax.xml.namespace.QName; import org.apache.axis2.AxisFault; import org.apache.axis2.address ...