12345 |
- // union-find set: the array contains the parent of each node
- // path compression but no balancing
- int make(int *C, int n) { for(int i = 0; i < n; i++) C[i]=i; }
- int find(int *C, int x) { return (C[x]==x) ? x : C[x]=find(C, C[x]); }
- void unite(int *C, int x, int y) { C[find(C, x)] = find(C, y); }
|