poj 2524
来源:互联网 发布:国外数据可视化公司 编辑:程序博客网 时间:2024/06/06 02:10
并查集 水题
#include<stdio.h>
#define MAX 100005int father[MAX];
int count;
int Find_Set(int x)
{
if(x!=father[x])
{
father[x]=Find_Set(father[x]);
}
return father[x];
}
void Union(int x,int y)
{
x=Find_Set(x);
y=Find_Set(y);
if(x!=y)
father[x]=y;
}
int main()
{
int n,m,i,x,y,count,num=1;
while(scanf("%d%d",&n,&m),n||m)
{
count=0;
for(i=1;i<=n;i++)
father[i]=i;
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
Union(x,y);
}
for(i=1;i<=n;i++)
{
if(father[i]==i)
count++;
}
printf("Case %d: %d\n",num++,count);
}
return 0;
}
- poj 1988 &&poj 2524
- POJ 2524
- poj 2524
- poj 2524
- poj 2524
- poj 2524
- poj--2524
- poj-2524
- poj 2524
- poj 2524
- POJ 2524
- POJ 2524
- POJ 2524
- POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- POJ-2524 Ubiquitous Religions
- WINCE 给命令条添加按钮和加载图片
- Uploadify 配置错误信息提示
- Colorization, Gray, Color-to-Gray, Color Models
- SDL学习笔记三(文字的显示)
- iOS 网络编程实践--NSStream实现TCP Socket iPhone客户端 .
- poj 2524
- wince 静态文本框字体和颜色、背景色的动态更改
- UIResponder UITouch
- jsp的request及增进研究【1】--资料准备
- 在窗体上放置一个菜单、一个工具栏控件,工具栏上有两个按钮,分别对应“打开文本文件”、“保存文本文件”
- DP(7)Post Office 1160
- WINCE 检测SD卡
- ajax值数据传递
- Fedora 安装问题