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. 斐波那契数列【java实现】

    java 实现斐波那契数列 以下是Java代码实现(递归与递推两种方式): import java.util.Scanner; /** * Fibonacci * * @author tongqian ...

  2. aapt.exe finished with non-zero exit value 1

    在一个APP 中导入 严振杰的 ALBUM,出现错误 在网上找了各种,最后在 stackoverflow上找到这样的说法: -Go to File->project structure-> ...

  3. mysql配置jdbc

    jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/database?useUnicode=t ...

  4. 构建第一个Spring Boot2.0应用之项目创建(一)

     1.开发环境 IDE: JAVA环境: Tomcat: 2.使用Idea生成spring boot项目 以下是使用Idea生成基本的spring boot的步骤. (1)创建工程第一步 (2)创建工 ...

  5. 初学者:Git常用命令总结

    git init      在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹.   git clone      获取一个u ...

  6. iOS核心动画高级技巧之图层变换和专用图层(二)

    iOS核心动画高级技巧之CALayer(一) iOS核心动画高级技巧之图层变换和专用图层(二)iOS核心动画高级技巧之核心动画(三)iOS核心动画高级技巧之性能(四)iOS核心动画高级技巧之动画总结( ...

  7. meterpreter > screenshot

    meterpreter > screenshotScreenshot saved to: /opt/metasploit/msf3/wLafQYhx.jpegmeterpreter > / ...

  8. SqlServer图形数据库初体验

    SQL Server2017新增了一个新功能叫做图形数据库.图形指的拓扑图形,是一些Node表和Edge表的合集,Node对应关系数据库中的实体,比如一个人.一个岗位等,Edge表指示Node之前的关 ...

  9. pta 编程题21 公路村村通

    其它pta数据结构编程题请参见:pta 题目 这道题考察最小生成树问题,用的是Prim算法. 和Dijkstra算法相比,没有了collect数组,因为dist[v] == 0就代表v被已收录. #i ...

  10. JavaScript:理解worker事件api

    如果你不是很了解Event事件,建议先看我上一篇随文javascript:理解DOM事件.或者直接看下文worker api. hack 首先,我们需要实例一个Worker的对象,浏览器会根据新创建的 ...