public int FindCircleNum(int[][] isConnected) { if (isConnected.Length == 0 || isConnected == null) { return(0); } UnionSet set = new UnionSet(isConnected.Length); for (int row = 0; row < isConnected.Length; row++) { for (int col = 0; col < isConnected[row].Length; col++) { if (isConnected[row][col] == 1 && row != col) { set.Union(row, col); } } } return(set.GetSets()); }