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. 根据要求完成表单以及使用servlet处理表单 任务要求 掌握Servlet输出表单和接收表单数据(多值组件的读取)。

    Servlet代码: package com.test; import java.io.IOException; import java.io.PrintWriter; import java.uti ...

  2. Spring MVC中注解的简介

    参考网址:  https://blog.csdn.net/a67474506/article/details/46361195 @RequestMapping映射请求 SpringMVC 使用 @Re ...

  3. 美国绿卡基础知识:I-539和I-129表格的应用回复新帖

    美国绿卡基础知识:I-539和I-129表格的应用 发布于: 2011/07/25  8:43 am 引用     I-539,就是和万金油类似的表格.不管你是要延期,还是转换身份:不管你是 B-2 ...

  4. Command Line Client(建库,建表)

    Enter password: ******Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection ...

  5. java的图形界面初学惯用

    1.单一界面的创建 public void mainFrame() { HashMap<String, Component> views = new HashMap<String, ...

  6. Javascript 向量

    向量 既有大小又有方向的量叫做向量(亦称矢量),与标量相对,用JS实现代码如下,直接搬miloyip的了 Vector2 = function(x, y) { this.x = x; this.y = ...

  7. POJ 1703 Find them, Catch them(并查集,等价关系)

    DisjointSet保存的是等价关系,对于某个人X,设置两个变量Xa,Xb.Xa表示X属于a帮派,Xb类似. 如果X和Y不是同一个帮派,那么Xa -> Yb,Yb -> Xa... (X ...

  8. tableviewcell折叠问题,(类似qq列表展开形式) 多个cell同时展开,OC版 和 Swift

    之前没有用到过这块,但是今天看到,就试了试,但是发现,网上的有的方法不能多个cell同时展开,只能一个一个的展开. 我就尝试用用数组记录展开的标记的方法,功能实现了, 直接上代码: // // Vie ...

  9. 问题 B: Curriculum Vitae

    问题 B: Curriculum Vitae 时间限制: 1 Sec  内存限制: 128 MB提交: 109  解决: 25[提交][状态][讨论版][命题人:acm4302] 题目描述 Hideo ...

  10. python_13_break

    for i in range(5): print('-----------',i) for j in range(5): print(j) if j>2: break####结束当前循环