find :: (PrimMonad m, R.MonadRef r m) => UFSet r m -> Int -> m Int
find ufs u = do
  f <- MV.unsafeRead (ufsSet ufs) u
  if u == f
    then return u
    else do
      f' <- find ufs f
      MV.unsafeWrite (ufsSet ufs) u f'
      return f'
find :: (PrimMonad m, R.MonadRef r m) => UFSet r m -> Int -> m Int
find ufs u = do
  f <- MV.unsafeRead (ufsSet ufs) u
  if u == f
    then return u
    else do
      f' <- find ufs f
      MV.unsafeWrite (ufsSet ufs) u f'
      return f'
find ufs u = do
  f <- MV.unsafeRead (ufsSet ufs) u
  if u == f
    then return u
    else do
      f' <- find ufs f
      MV.unsafeWrite (ufsSet ufs) u f'
      return f'