HDU 1213 How Many Tables
来源:互联网 发布:域名 许扬 编辑:程序博客网 时间:2024/06/14 21:37
HDU 1213 How Many Tables
考察基础的并查集。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<string>#include<math.h>using namespace std;int m,n;int per[1005];void init()//初始化;{ for(int i = 0; i <= n; i ++) { per[i] = i; }}int find(int x)//寻找根节点;{ int i = x,j,k; while(per[i] != i) { i = per[i]; } return i;}void join(int x,int y)//合并;{ int s = find(x); int e = find(y); if(s != e) { per[s] = e; }}int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); init(); int a,b; for(int i = 1; i <= m; i ++) { scanf("%d%d",&a,&b); join(a,b); } int cnt = 0; for(int i = 1; i <= n; i ++) { if(per[i] == i) cnt ++; } printf("%d\n",cnt); } return 0;}
如有错误,欢迎指出~
1 0
- hdu 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- Hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213how many tables
- hdu 1213 How Many Tables
- Hdu 1213 - How Many Tables
- HDU 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- 十二、Mysql 日期处理
- HDU 2116 JAVA
- linux 虚拟机管理(unit15)
- HDU 2117 JAVA
- web.xml是什么?web.xml详解。
- HDU 1213 How Many Tables
- C++智能指针干货
- 分布式消息系统ActiveMQ
- HDU 2123 JAVA
- pwn100 ssp
- v$parameter,v$system_parameter及v$spparameter的区别
- 各个分类算法优缺点
- JSP注释
- hibernate实现多表联合查询