Trace [[0,0],[0,2],[1,1],[2,0],[2,2]].
Stone 0: (0,0). Stone 1: (0,2). Stone 2: (1,1). Stone 3: (2,0). Stone 4: (2,2).
Stones 0 and 1 share row 0. Union them.
Stones 0 and 3 share column 0. Union them (0,1,3 now connected).
Stones 1 and 4 share column 2. Union them (0,1,3,4 now connected).
Stone 2 at (1,1) shares nothing with others. Alone.
Components: {0,1,3,4}, {2}. Count: .
Removals: .
time comparing all pairs. space.