How Many Tables hdu1213 并查集
来源:互联网 发布:手机淘宝推广平台 编辑:程序博客网 时间:2024/05/16 07:33
http://acm.hdu.edu.cn/showproblem.php?pid=1213
。。。好久没写代码了。= =。 非常简单的并查集。
#include <iostream>using namespace std;#define N 1003int people[N];int findfather(int n){if (n!=people[n])people[n]=findfather(people[n]);return people[n];}int main(){#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endifint t,n,m,i,a,b,sum;scanf("%d",&t);while (t--){scanf("%d%d",&n,&m);for (i=1;i<=n;i++)people[i]=i;while (m--){scanf("%d%d",&a,&b);a=findfather(a);b=findfather(b);if (a!=b)people[b]=a;}sum=0;for (i=1;i<=n;i++)if (people[i]==i)sum++;printf("%d\n",sum);}return 0;}
- 【hdu1213】How Many Tables【并查集】
- How Many Tables hdu1213 并查集
- hdu1213(How Many Tables 并查集)
- Hdu1213 - How Many Tables - 并查集
- HDU1213 How Many Tables 【并查集】
- HDU1213 How Many Tables【并查集】
- HDU1213 How Many Tables 【并查集】
- hdu1213 How Many Tables(并查集)
- How Many Tables--hdu1213(并查集)
- HDU1213-How Many Tables 并查集
- HDU1213 How Many Tables - 并查集
- hdu1213 How Many Tables 并查集
- HDU1213 How Many Tables(并查集)
- HDU1213 How Many Tables 并查集
- hdu1213 How Many Tables 并查集
- HDU1213 How Many Tables(并查集)
- hdu1213 How many tables 并查集
- HDU1213 How Many Tables 并查集
- Jquery判断radio,selelct,checkbox是否选中及选中的值
- 每天看懂一个电路图
- MySQL 触发器简单学习
- Spring与EJB的整合(关键部分)
- Linux在工作中的常用命令和设置(陆续追加中...)
- How Many Tables hdu1213 并查集
- matcom数据 Mm转 int和Cstring
- 北邮-上机-提交错误解决及一些经验
- C++ win32 开发 GDIPlus 贴图
- java 批量重命名文件
- VC里的"#define new DEBUG_NEW"
- HDU1542--Atlantis
- 牢记25个最佳的SSH命令
- 用链表实现栈C++实现源码