模板-并查集
2016-09-30 21:42
288 查看
#include <iostream> using namespace std; int father[100]; //初始化 void init() { for(int i = 0; i < 100; ++ i) { father[i] = i; } } //查找根节点,按路径优化 int find(int node) { if(father[node] != node) { father[node] = find(father[node]); } return father[node]; } //合并 void unit(int x, int y) { int x0 = find(x); int y0 = find(y); father[y0] = x0; }
相关文章推荐
- 并查集模板
- 洛谷 P3367 并查集【模板】
- 并查集(Union-Find Set)模板
- 【并查集入门专题1】A+B+D 三道模板题 hdu1232 hdu1233 poj2524【并查集模板】
- POJ 2524 宗教信仰 并查集 基础模板
- 并查集模板
- [poj 1611]The Suspects[并查集模板][递归与非递归实现]
- 并查集模板
- HDU 1232 畅通工程 【并查集模板】
- 模板:并查集
- kruskal_并查集_代码模板 &hdu1232
- 【模板】并查集
- hdu 1856 More is better 并查集模板题
- 模板--并查集
- POJ-1611 The Suspects (并查集模板题)
- HDU 1213 How Many Tables(并查集模板)
- nyist 608 并查集模板
- 并查集(模板)
- 【模板】并查集
- 【并查集模板】 【洛谷P2978】 【USACO10JAN】下午茶时间