Ice_cream's world I

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1
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>
int wall[];
int find(int x){
int r=x;
while(r!=wall[r])r=wall[r];
int i=x,j;
while(i!=r)j=wall[i],wall[i]=r,i=j;
return r;
}
int main(){
int N,M,temp1,temp2,f1,f2,flot;
while(~scanf("%d%d",&N,&M)){
for(int i=;i<N;++i)wall[i]=i;
flot=;
while(M--){
scanf("%d%d",&temp1,&temp2);
f1=find(temp1);f2=find(temp2);
if(f1!=f2)wall[f1]=f2;
else flot++;
}
printf("%d\n",flot);
}
return ;
}

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

  1. A - Ice_cream’s world III

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

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

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

  5. hdoj 2122 Ice_cream’s world III

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

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

  7. Ice_cream's world I--hdu2120

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

  8. Ice_cream’s world III(prime)

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

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

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

随机推荐

  1. 创建UILabel

    UILabelCreate.h #import <UIKit/UIKit.h> @interface UILabelCreate : UILabel /** * 创建UILabel 初始化 ...

  2. class、interface、struct的差别

    1 struct和class有什么差别 1.1默认的继承訪问权限 Struct是public的,class是private的. 你能够写例如以下的代码: struct A { char a; }; s ...

  3. mbed OS - ARM关于物联网(IoT)的战略布局

    关于IoT 在刚刚过去的ARMTECHCON2014(Santa Clara Convention Center)第1天会议,首要的keynote就是ARM针对建立物联网(InternetOf Thi ...

  4. Android应用程序内部启动Activity过程(startActivity)的源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6703247 上文介绍了Android应用程序的 ...

  5. 【HDU】 1018 Big Number

    大意就是求 : log10(n!) = log10(1 * 2 *  3 * .......*n) = log10(1) + log10(2) + ........+log10(n); 打表的话会ML ...

  6. 包含深度学习常用框架的Docker环境

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ All in one d ...

  7. 虚拟化之docker安装篇

    1,docker pull centos     下载centos镜像 docker search centos  搜索镜像 2,docker images           查看本地镜像 3,do ...

  8. XML读写

    private string fileName = HttpContext.Current.Server.MapPath("~/Student.xml"); protected v ...

  9. iOS archive(归档)的总结

    http://www.cnblogs.com/ios8/p/ios-archive.html

  10. “有箭头的视图”,即程序的Storyboard Entry Point。

    设置方法很简单:打开StoryBoard文件,选中要设置为第一视图的ViewController,在右边工具栏勾选Is Initial View Controller就好了,此时你会看到ViewCon ...