@ Override public boolean union ( int x , int y ) { int rx = x ; int ry = y ; int px = p [ rx ] ; int py = p [ ry ] ; while ( px != py ) { if ( px < py ) { if ( rx == px ) { p [ rx ] = py ; return true ; } p [ rx ] = py ; rx = px ; px = p [ rx ] ; } else { if ( ry == py ) { p [ ry ] = px ; return true ; } p [ ry ] = px ; ry = py ; py = p [ ry ] ; } } return false ; }
Unites the sets containing the two given elements .