Algorithm Identifying

Правка en1, от aarshee, 2015-06-14 17:12:11

What is the algorithm for merging two different sets ?

inline int find(int x){ return (parent[x] == x ? x : find(parent[x])); }

inline bool merge(int x, int y){ x = find(x); y = find(y); if(x == y) return false; if(r[x] > r[y]) x = y + x — (y = x); parent[x] = y; if(r[x] == r[y]) r[y]++; return true; }

Thanks in advance.

Теги algorithms, sets, merge-find set

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский aarshee 2015-06-14 17:12:11 374 Initial revision (published)