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


大意:有n个碉堡,m种关系每个关系表示两个碉堡连在一起,问一共有多少环。
父结点相等就有一个环。
 #include<cstdio>
int n,m,fa[],i,a,b,sum;
int find(int a)
{
int r=a;
while(r != fa[r])
{
r=fa[r];
}
int i=a,j;
while(i != r)
{
j=fa[i];
fa[i]=r;
i=j;
}
return r;
}
void f1(int x,int y)
{
int nx,ny;
nx=find(x);
ny=find(y);
if(nx != ny)
{
fa[nx]=ny;
}
else
{
sum++;
}
}
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
sum=;
for(i = ; i < n ; i++)
{
fa[i]=i;
}
for(i = ; i < m ; i++)
{
scanf("%d %d",&a,&b);
f1(a,b);
}
printf("%d\n",sum);
}
}

 

最新文章

  1. ZOJ Problem Set - 1292 Integer Inquiry
  2. iOS支持Https
  3. [mysql] Some non-transactional changed tables couldn&#39;t be rolled back
  4. 将服务器返回的URL或者网址截取出来特定的字符,然后将字符返回,一般根据返回的字符判断用户是否登录等即时状态
  5. Android进阶笔记18:选用合适的IPC方式
  6. C语言中时间调用处理的相关函数介绍
  7. 怎么样调试正在运行的exe?
  8. [git] git 分支管理和工作流程
  9. 如何编写一个简单的makefile
  10. 洛谷 P1515 旅行
  11. CSS基础3——使用CSS格式化元素内容的字体
  12. MyEclipse10.0 集成 SVN
  13. PLSQL程序流程
  14. hdu3746 kmp求循环节
  15. Python-WXPY实现微信监控报警
  16. [转载] Java集合---HashMap源码剖析
  17. linux中 probe函数的何时调用的?
  18. JavaWeb之html
  19. rem实现移动端自适应页面
  20. 在linux中配置mysql的过程

热门文章

  1. ie下,php HTTP_REFERER获取失败的整理
  2. 【bzoj2084】[Poi2010]Antisymmetry
  3. P2955 [USACO09OCT]奇数偶数Even? Odd?
  4. laravel如何查找门脸及注入类方法
  5. java语言基础-类型运算细节
  6. COGS 1570. [POJ3461]乌力波
  7. Linux之 if命令——简单的shell文件
  8. Python3简明教程(十四)—— Collections模块
  9. exit - 使程序正常中止
  10. python基础一 day5 知识点