CF1624G.MinOr Tree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently, Vlad has been carried away by spanning trees, so his friends, without hesitation, gave him a connected weighted undirected graph of n vertices and m edges for his birthday.
Vlad defined the ority of a spanning tree as the bitwise OR of all its weights, and now he is interested in what is the minimum possible ority that can be achieved by choosing a certain spanning tree. A spanning tree is a connected subgraph of a given graph that does not contain cycles.
In other words, you want to keep n−1 edges so that the graph remains connected and the bitwise OR weights of the edges are as small as possible. You have to find the minimum bitwise OR itself.
输入格式
The first line of the input contains an integer t ( 1≤t≤104 ) — the number of test cases in the input.
An empty line is written in front of each test case.
This is followed by two numbers n and m ( 3≤n≤2⋅105,n−1≤m≤2⋅105 ) — the number of vertices and edges of the graph, respectively.
The next m lines contain the description of the edges. Line i contains three numbers vi , ui and wi ( 1≤vi,ui≤n , 1≤wi≤109 , vi=ui ) — the vertices that the edge connects and its weight.
It is guaranteed that the sum m and the sum n over all test cases does not exceed 2⋅105 and each test case contains a connected graph.
输出格式
Print t lines, each of which contains the answer to the corresponding set of input data — the minimum possible spanning tree ority.
输入输出样例
输入#1
3 3 3 1 2 1 2 3 2 1 3 2 5 7 4 2 7 2 5 8 3 4 2 3 2 1 2 4 2 4 1 2 1 2 2 3 4 1 2 1 2 3 2 1 3 3 3 1 4
输出#1
2 10 3
说明/提示
Graph from the first test case.
Ority of this tree equals to 2 or 2 = 2 and it's minimal.
Without excluding edge with weight 1 ority is 1 or 2 = 3.