MinOr Tree solution codeforces
Recently, Vlad has been carried away by spanning trees, so his friends, without hesitation, gave him a connected weighted undirected graph ofvertices and 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 keepedges 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( ) — the number of test cases in the input.
An empty line is written in front of each test case.
This is followed by two numbersand ( ) — the number of vertices and edges of the graph, respectively.
The nextlines contain the description of the edges. Line contains three numbers , and ( , , ) — the vertices that the edge connects and its weight.
It is guaranteed that the sumand the sum over all test cases does not exceed and each test case contains a connected graph.
Print ority.lines, each of which contains the answer to the corresponding set of input data – the minimum possible spanning tree
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
output MinOr Tree solution codeforces
2 10 3