Updated. Now the program can solve the problem correctly. Still need to compare between QuickUnionFind and WeighedQuickUnionFind...