Have to rework solution using disjoint set