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. arcpy批量打印地图

    有个处理数据的需求是把一个图层中的要素单独显示在底图上,设置固定的比例尺,并打印出图片. 考虑到后续会有重复的大量的数据要处理,决定使用arcpy处理. 首先新建一个mxd底图文档,把需要打印的地图都 ...

  2. 微控制器(MCU)破解秘笈--背景知识

    2.1 硅芯片安全措施的演变 工业控制器的硬件安全措施与嵌入式系统同时开始发展.三十年前的系统是由分离的部件如CPU,ROM,RAM,I/O缓冲器,串口和其他通信与控制接口组成的.如图2-1所示: 图 ...

  3. Qt Project的持续集成方案

    作者:齐亮链接:http://www.zhihu.com/question/24314354/answer/27547787来源:知乎著作权归作者所有,转载请联系作者获得授权. PETER HARTM ...

  4. 认识元数据和IL(上) <第三篇>

    说在,开篇之前 很早就有说说Metadata(元数据)和IL(中间语言)的想法了,一直在这篇开始才算脚踏实地的对这两个阶级兄弟投去些细关怀,虽然来得没有<第一回:恩怨情仇:is和as>那么 ...

  5. 转:ReportViewer控件使用方法

    a. ReportViewer关联Report1.rdlc的简单呈现b. 对带有报表参数的Report1.rdlc的呈现c. 利用程式生成的DataSet 填充报表d. 调用存储过程 生成DataSe ...

  6. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  7. LaTex 下编译后不能显示中文,或者中文乱码

    在 Sublime Text 中编辑以下文件并保存(第一行的注释很重要),按下 Cammand + B 编译: %!TEX program = xelatex \documentclass[UTF8] ...

  8. 网易云课堂_C++开发入门到精通_章节6:多态

    课时33示例--为多态基类声明虚析构函数 微软校园招聘笔试题 #include <iostream> class Base { public: char Value() { return ...

  9. jquery 绑定动态元素

    以一个小例子来简单说明下情况 ? 1 2 3 4 5 6 7 8  <script src="jquery-1.11.0.min.js"></script> ...

  10. 关于map与set的一点理解;

    set代码: #include<stdio.h> #include<set> using namespace std; int main(){ set<int>m; ...