Initialise a new union find data structure with s nodes
(s int)
| 23 | |
| 24 | // Initialise a new union find data structure with s nodes |
| 25 | func NewUnionFind(s int) UnionFind { |
| 26 | parent := make([]int, s) |
| 27 | rank := make([]int, s) |
| 28 | for i := 0; i < s; i++ { |
| 29 | parent[i] = i |
| 30 | rank[i] = 1 |
| 31 | } |
| 32 | return UnionFind{parent, rank} |
| 33 | } |
| 34 | |
| 35 | // Find finds the root of the set to which the given element belongs. |
| 36 | // It performs path compression to make future Find operations faster. |
no outgoing calls