A solution to POJ 1703, using Union Find Set