Disjoint set union (DSU)
DisJoint set union : It is a technique in graphs used for grouping problems
There are two functions used (find and union )
Find: find parent;
Union: merge two groups with a rule;
public int find(int x,int[] par){
if(par[x]==x){return x;}par[x]=find(par[x],par);return par[x];}public void union(int x,int y,int[] par){int px = find(x,par);int py = find(y,par);if(px!=py){if(px<py){par[py]=px;}else{par[px]=py;} } }