xfstart07
Get busy living or get busy dying

#include < iostream >
using   namespace  std;

struct  arr{
    
int  x,y,c;
}a[
25000 ];
int  N,k,m;
int  p[ 10010 ];
int  Find( int  x){
    
if (x != p[x]) p[x] = Find(p[x]);
    
return  p[x];
}
int  main()
{
    scanf(
" %d%d%d " , & N, & k, & m);
    
for ( int  i = 1 ;i <= k; ++ i){
        scanf(
" %d%d " , & a[i].x, & a[i].y);
        a[i].c
= 0 ;
    }
    
for ( int  i = 1 ;i <= m; ++ i){
        scanf(
" %d%d " , & a[i + k].x, & a[i + k].y);
        a[i
+ k].c = 1 ;
    }
    
for ( int  i = 1 ;i <= N; ++ i)
        p[i]
= i;
    
int  l = 0 ,ans = 0 ;
    
for ( int  i = 1 ;i <= k + m; ++ i){
        
int  x = Find(a[i].x),y = Find(a[i].y);
        
if (x != y){
            ans
+= a[i].c;
            l
++ ;
            
if (l == N - 1 break ;
            p[x]
= y;
        }
    }
    printf(
" %d\n " ,ans);
    
return   0 ;
}




posted on 2009-06-03 18:28 xfstart07 阅读(476) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理