added quick-union UF data structure, with optimizations