LeetCode:https:// classSolution{publicintcountComponents(intn,int[][]edges){if(n<0||edges==null)return-1;UnionFinduf=newUnionFind(n);for(varedge:edges){// 当两个点从不连通变为连通时,则减少了一个独立连通域if(uf.union(edge[0],edge[1])){n--;}}returnn;}}classUnionFind{introot[]...