拓展:Find 操作的优化(压缩路径)
压缩路径——Find 操作,先找到根结点,再将查找路径上所有的结点都挂到根结点下
int Find(int S[], int x){
	int root = x;
	while(S[root] >= 0) root = S[root];  // 循环找到根
	while(x != root){  // 父结点
		int t = S[x];  // t 指向 x 的父结点
		S[x] = root;  // x 直接挂到根结点下
		x = t;
	}
	return root;  // 返回根结点编号
}
 
每次 Find 操作,先找根,再 “压缩路径” ,可使树的高度不超过  
     
      
       
       
         O 
        
       
         ( 
        
       
         α 
        
       
         ( 
        
       
         n 
        
       
         ) 
        
       
         ) 
        
       
      
        O(\alpha(n)) 
       
      
    O(α(n)) 。 
     
      
       
       
         α 
        
       
         ( 
        
       
         n 
        
       
         ) 
        
       
      
        \alpha(n) 
       
      
    α(n) 是一个增长很缓慢的函数,对于常见的 n 值,通常  
     
      
       
       
         α 
        
       
         ( 
        
       
         n 
        
       
         ) 
        
       
         ≤ 
        
       
         4 
        
       
      
        \alpha(n)\leq4 
       
      
    α(n)≤4 ,因此优化后并查集的 Find、Union 操作时间开销都很低









