杭电 1213 How Many Tables
来源:互联网 发布:梦幻群侠传3优化版攻略 编辑:程序博客网 时间:2024/05/02 01:22
#include"stdio.h"
#define N 1050
int s[N];
void chushihua()
{
int i;
for(i=0;i<N;i++)
s[i]=i;
}
int find(int x)
{
while(s[x]!=x) x=s[x];
return x;
}
int fri(int x,int y)
{
if(find(x)!=find(y))
{
s[find(y)]=find(x);//不要误认为是他们俩个认亲的方式是他们俩的事,而是从他们老大下手,他们老大亲了他们就亲了
return 1;
}
return 0;
}
int main()
{
int m,n;
scanf("%d",&m);
int a,b;
int c1,c2;
while(m--)
{
int sum=0;
chushihua();
scanf("%d %d",&a,&b);
int i,j;
for(i=1;i<=b;i++)
{
scanf("%d%d",&c1,&c2);
sum=sum+fri(c1,c2);
}
/* for(j=1;j<=a;j++)
{
if(s[j]==j)
sum++;
}
*/
printf("%d\n",a-sum);
}
return 0;
}
- 杭电acm 1213 (How many tables)
- 杭电1213-How Many Tables
- 杭电 1213 How Many Tables
- 【杭电1213】How Many Tables
- 杭电1213How Many Tables
- 【杭电】[1213]How Many Tables
- 杭电1213 How many tables
- 杭电oj--1213 How Many Tables
- 杭电hdu 1213 How Many Tables并查集
- HDOJ 1213 How Many Tables 杭电 ACM
- 杭电1213 How Many Tables(并查集)
- 杭电 HDU ACM 1213 How Many Tables
- hdu杭电1213 How Many Tables【并查集】
- 杭电 1213 How Many Tables 并查集
- 杭电1213 How Many Tables(并查集找根节点)
- 杭电1213How Many Tables与杭电1232大同小异
- How Many Tables 1213
- 1213 How Many Tables
- 杭电1233还是畅通工程
- spring事务管理
- hdu-oj 1302 The Snail
- [水]ZOJ1241
- HDU 3255 Farming
- 杭电 1213 How Many Tables
- hdu 4920矩阵乘法
- emacs 无法复制 复制不了
- Handler MessageQueue Looper
- 微软正式发布Visual Studio 2013 Update 3 (2013.3) RTM
- iOS开发---网址收藏
- 2014最赚钱项目 加值电话设备
- spring依赖注入枚举类型
- c、c++ 结构体的嵌套