设为首页 加入收藏

TOP

HDU 1325 Is It A Tree? 并查集
2015-07-20 18:04:14 来源: 作者: 【 】 浏览:2
Tags:HDU 1325 Tree 查集

判断是否为树

森林不是树

空树也是树

成环不是树

数据:

1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 1 0 0

1 2 2 3 4 5 0 0

2 5 0 0

ans:

no

no

yes

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               using namespace std; typedef long long LL; const int maxn =10000+5; const int maxe = 15000+5; const int INF = 460002326; const int mod = 1000000009;//q[i]表示点i 对应的点 rank[i]表示入度 int fa[maxn],q[maxn],rank[maxn],taj,flag;//taj表示当前点的编号个数 void init() { flag=0; taj=1; for(int i=0; i
              
               =0) { init();//初始化 if(a==0&&b==0)// 0 0 也算树 { printf("Case %d is a tree.\n",++cas); continue; } a=q[a],b=q[b]; merge(a,b); while(scanf("%d%d",&a,&b)) { if(a+b==0) break; dian(a,b); a=q[a],b=q[b]; merge(a,b); } a=0; for(int i=1; i
               
                1) flag=1; } printf("Case %d is ",++cas); if(a==1&&flag==0&&taj>2) puts("a tree."); else puts("not a tree."); } return 0; } 
               
              
             
            
           
          
         
        
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu4864Task(贪心) 下一篇UVA 1356 - Bridge(自适应辛普森)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: