Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Given an undirected tree with N nodes rooted at 1. Every node is assigned a weight which is given by an array A. Weight of an edge W(u, v) is defined as (A[u] + A[v]) * (A[u] | A[v]), where | represents Bitwise OR operator.
You are allowed to perform at most K operations on tree and in each operation:
Suppose, X such operations are performed, maximize the value of Z = (Sum of weight of all the edges of the tree) * (K - X + 1)
Input Format:
Output Format:
Constraints:
N=104K=1021≤A[i]≤1061≤u,v≤N
Verdit and Scoring
Given X = 1. After operation is applied:
Now, weight of edges are:
Value of Z = 124* (2 - 1 + 1) = 248.
Please note: Sample Input / Output is just for the purpose of understanding. Test files follow the constraints specificed in problem statement.