hdu_1213 how many tables (并查集)
来源:互联网 发布:网络协议配置命令行 编辑:程序博客网 时间:2024/06/08 18:35
http://acm.hdu.edu.cn/showproblem.php?pid=1213
分析: 并查集模板题,所以就不多分析了
代码:
#include <iostream>#include <cstdio>#include <string.h>using namespace std;#define M 1010int n,m;int parent[M];int Find(int e){ if(parent[e]!=e) parent[e]=Find(parent[e]); return parent[e];}void Union(int x,int y){ int r1=Find(x); int r2=Find(y); if(r1!=r2) parent[r2]=r1;}int calc(){ int ans=0; for(int i=1;i<=n;i++) if(parent[i]==i) ans++; return ans;}int main(){ // freopen("in.txt","r",stdin); int t; int a,b; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) parent[i]=i; for(int i=0;i<m;i++){ scanf("%d%d",&a,&b); Union(a,b); } printf("%d\n",calc()); } return 0;}
0 0
- hdu_1213 how many tables (并查集)
- hdu_1213 How Many Tables
- 【hdu1213】How Many Tables【并查集】
- How Many Tables(并查集)
- How Many Tables hdu1213 并查集
- hdu1213(How Many Tables 并查集)
- Hdu1213 - How Many Tables - 并查集
- HDU1213 How Many Tables 【并查集】
- 并查集---How Many Tables
- HDU1213 How Many Tables【并查集】
- HDU1213 How Many Tables 【并查集】
- [并查集]How Many Tables
- hdu1213 How Many Tables(并查集)
- hdoj How Many Tables【并查集】
- hdoj1213 How many tables?(并查集)
- How Many Tables-并查集
- HDOJ1213 How Many Tables(并查集)
- How Many Tables--hdu1213(并查集)
- iOS 画圆弧或扇形
- linux shell 自定义函数(定义、返回值、变量作用域)介绍
- 女车主服毒自杀?
- 格式化原理
- 全局变量的定义
- hdu_1213 how many tables (并查集)
- pydev开发python快捷键
- LBE 安全大师支持android 4.4注入分析
- GlusterFS原创资源汇总
- iOS解析HTML
- ACM-2001-计算两点间的距离
- 无人区好不好看呀?
- MySQL 读写分离
- 如果是初学C语言请看完 一些成功人士的心得