Ice_cream’s world I

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

题意:构成了几个环。

题解:

void mix(int a,int b)
{
int x;
int y;
x=find(a);
y=find(b);
if(x!=y)
road[x]=y;
else
ans++; } 这里这样写就OK
#include<stdio.h>
int road[1010];
int ans;
int find(int a)
{
if(road[a]==a) return a;
else
return find(road[a]);
}
void mix(int a,int b)
{
int x;
int y;
x=find(a);
y=find(b);
if(x!=y)
road[x]=y;
else
ans++; }
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
for(int i=0;i<=n-1;i++)
road[i]=i;
int a, b;
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
mix(a,b);
}
printf("%d\n",ans);
}
}

HDOJ 2120 Ice_cream's world I的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdoj 2121 Ice_cream’s world II 【没有最低树的根节点】

    称号:pid=2121" target="_blank">hdoj 2121 Ice_cream's world II 题意:题目是一道躶题,给n个点,m条边的有向 ...

  4. hdoj 2122 Ice_cream’s world III

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

  5. HDOJ 2120 并查集

    并查集的应用,用来查找被分割的区域个数. 即当两个节点值相同时说明已经为了一个圈,否则不可能,此时区域个数加1. #include<iostream> #include<cstdio ...

  6. HDU 2120 Ice_cream&#39;s world I(并检查集合)

    职务地址:HDU 2120 这题尽管字数不多,但就是看不懂. . 意思是求最多有多少个被墙围起来的区域.显然就是求环的个数.然后用并查集求环个数就能够了. 代码例如以下: #include <i ...

  7. 杭电 2120 Ice_cream's world I (并查集求环数)

    Description ice_cream's world is a rich country, it has many fertile lands. Today, the queen of ice_ ...

  8. HDU 2120 Ice_cream's world I【并查集】

    解题思路:给出n对点的关系,求构成多少个环,如果对于点x和点y,它们本身就有一堵墙,即为它们本身就相连,如果find(x)=find(y),说明它们的根节点相同,它们之间肯定有直接或间接的相连,即形成 ...

  9. hdoj 2122 Ice_cream’s world III【最小生成树】

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

随机推荐

  1. 修改response,报错Cannot call getWriter(), getOutputStream() already called

    往response里面改数据,然后系统报这个错 此时直接return null即可解决 但是,要想返回相应的页面呢? 可以直接在response里设置返回的页面

  2. C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法

    C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法 Bitmap类:此类封装了GDI+中的一个位图,次位图有图形图像及其属性的像素数据组成.因此此类是用于处理像素数据定义的图形的对象.该类的 ...

  3. css盒子模型 css3盒子相关样式

    1.内边距(内边距在content外,边框内) 内边距属性: padding          设置所有边距 padding-bottom     底边距 padding-left           ...

  4. servlet传值到servlet传值问题

    今天在项目中遇到一个问题:中期项目自己做的新闻部分NewsPagerSortservlet传值时,正确答案如下 if(title!=""){ resp.sendRedirect(& ...

  5. 面向对象(OOP)三

    一.面向对象基础原则 1)单一职责原则(类要写得小而精,低耦合) 内部类 单列模式 对于单一职责原则,其核心思想为:一个类,最好只做一件事,只有一个引起它的变化.单一职责原则可以看做是低耦合.高内聚在 ...

  6. JavaScript初始

    一.JavaScript基础 1.引入方式 <!--1 直接编写--> <script> alert('hello yuan') </script> <!-- ...

  7. GoDaddy虚拟主机创建FTP 图文流程

    有了ftp各种操作就方便多了,也不用通过网页的控制面板来修改代码了 狗爹linux虚拟主机创建FTP 1. 通过虚拟主机管理界面,进入cPanel控制面板 2. 进入FTP管理页面 3. 填写账号.密 ...

  8. Java字节流与字符流的区别详解

    字节流与字符流 先来看一下流的概念: 在程序中所有的数据都是以流的方式进行传输或保存的,程序需要数据的时候要使用输入流读取数据,而当程序需要将一些数据保存起来的时候,就要使用输出流完成. 程序中的输入 ...

  9. 【iOS学习笔记】改变状态栏字体颜色

    Step1. info.plist中设置UIViewControllerBasedStatusBarAppearance为NO Step2. AppDelegate.m中添加 - (BOOL)appl ...

  10. apache日志设置

    转自:http://hi.baidu.com/bxhack/item/71025d3e65987d88b611db5e apache日志存放位置 Windows: <Apache安装目录> ...