Union | Naive implementation of find ; Naive implementation of union ( )
function find ( parent , i ) { if ( parent [ i ] == - 1 ) return i ; return find ( parent , parent [ i ] ) ; } function Union ( parent , x , y ) { let xset = find ( parent , x ) ; let yset = find ( parent , y ) ; parent [ xset ] = yset ; }