UnionFind.cc 208 B

123
  1. //union-find set: the vector/array contains the parent of each node
  2. int find(vector <int>& C, int x){return (C[x]==x) ? x : C[x]=find(C, C[x]);} //C++
  3. int find(int x){return (C[x]==x)?x:C[x]=find(C[x]);} //C