Added some comments.
Added union-find data structure.