bestcoder #72 DIV2 Clarke and MST 最大按位与的生成树

Clarke and MST

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 196    Accepted Submission(s): 100


Problem Description
Clarke is a patient with multiple personality disorder. One day he turned into a learner of graph theory. 
He learned some algorithms of minimum spanning tree. Then he had a good idea, he wanted to find the maximum spanning tree with bit operation AND. 
A spanning tree is composed by  n1  edges. Each two points of  n points can reach each other. The size of a spanning tree is generated by bit operation AND with values of  n1  edges. 
Now he wants to figure out the maximum spanning tree.
 

Input
The first line contains an integer  T(1T5) , the number of test cases. 
For each test case, the first line contains two integers  n,m(2n300000,1m300000) , denoting the number of points and the number of edge respectively.
Then  m lines followed, each line contains three integers  x,y,w(1x,yn,0w109) , denoting an edge between  x,y  with value  w
The number of test case with  n,m>100000  will not exceed 1. 
 

Output
For each test case, print a line contained an integer represented the answer. If there is no any spanning tree, print 0.
 

Sample Input
  
  
1 4 5 1 2 5 1 3 3 1 4 2 2 3 1 3 4 7
 

Sample Output
  
  
1
 

题目大意:

       最大生成树。挑选最大按位&的路线。


思路:用二进制的方法一个一个的判断最高位即可。






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值