HDOJ-1213(并查集)
来源:互联网 发布:淘宝里卖家正在被处罚 编辑:程序博客网 时间:2024/06/05 10:17
基本的并查集应用
#include <stdio.h>#include <string.h>#define MAX 50001int father[MAX];int Find(int x){ return father[x] ? father[x] = Find(father[x]) : x;}int Union(int x, int y){ int fx = Find(x), fy = Find(y); if(fx == fy) return fx; else return father[fy] = fx;}int main(){ int test = 0, n, m; int i, x, y, cnt; scanf("%d", &test); while(test--){ scanf("%d%d", &n, &m); /* initialize */ memset(father, 0, sizeof(int) * (n + 1)); cnt = 0; /* find and union */ for(i = 0; i < m; ++i){ scanf("%d%d", &x, &y); Union(x, y); } /* count how many trees there are */ for(i = 1; i <= n; ++i){ if(Find(i) == i) ++cnt;/* if i is a root node */ } printf("%d\n", cnt); } return 0;}
0 0
- HDOJ-1213(并查集)
- hdoj 1213并查集
- HDOJ 1213 How Many Tables(基础并查集)
- HDOJ 1213 How Many Tables(并查集)
- HDOJ 1213 How Many Tables(并查集)
- HDOJ 1213 How Many Tables(并查集)
- 并查集——HDOJ 1213
- 并查集(HDOJ 1856)
- HDOJ-1232(并查集)
- HDOJ 4707 Pet (并查集)
- hdoj tree 5606 (并查集)
- HDOJ-----2120并查集(水题)
- hdoj 1232+hdoj 1272 (并查集)
- hdoj 2473 并查集
- HDOJ - 3560 并查集
- HDOJ-1232(并查集)
- HDOJ-----1232并查集
- HDOJ-----5631并查集
- 谷歌地图在ArcGIS中如何将默卡托转成WGS84坐标系
- ognl.OgnlException
- 表单验证3
- 程序的模块化的一些见解5-移植性-实例说明
- LeetCodeOJ--Reverse Words in a String(python版本)
- HDOJ-1213(并查集)
- cg
- 代码就是把当前节点内所有进程遍历一遍,把进程状态写入到文本里面
- checkStyle配置说明、范例和结果分析
- bash: wget: command not found的解决办法
- 无限层级且乱序的树形结构数据的整理,利用HashMap减少遍历次数
- 字符串化操作符#,粘接附##,字符化操作符@#
- 【转】 LSD(Line Segment Detector) 直线段检测算法学习~
- FTP方式实现上传下载功能