并查集
代码模版
结构
1 | type UnionFind struct { |
初始化
1 | func NewUnioinFind(n int) *UnionFind{ |
查询(find)
1 | func(uf *UnionFind)find(x int)int{ |
按秩合并(unite)
1 | func(uf *UnionFind)unite(x, y int){ |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.