implemented using two quick-union structures