


Input: 'stones' = [[0,1] [1,0] [0,0]]
Output: 2
Explanation:
We can remove the 1st stone at [0,1] as it has the same row as the 3rd stone [0, 0]. And remove the 2nd stone because it has the same column [0,1] as the 3rd stone.
The first line of input contains a single integer 'n', which represents the number of stones.
The following 'n' lines of the input contain the coordinates of the stones, where each line contains two space-separated integers representing the row and column, respectively.
Return a single line containing a single integer denoting the maximum number of stones that can be removed.
You don't have to print anything. It's been already taken care of. Just implement the given function.
The main idea is to use a DSU data structure, to find connected components. A DSU data structure can be used to maintain knowledge of the connected components of a graph, and query for them quickly. In particular, we would like to support two operations:
Following are the steps :